Questions tagged [bash]

For questions about scripts written for the Bash command shell. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here. Questions about interactive use of Bash are more likely to be on-topic on Super User than on Stack Overflow.

Filter by
Sorted by
Tagged with
0
votes
0answers
11 views

Configuring a docker container to use host UID and generate files on the host system - Preferably at runtime

I am currently working on a research tool that is supposed to be containerized using docker to hopefully be run on as many different systems as possible. This works fine for the most part, we have run ...
1
vote
2answers
20 views

How to suppress the single quote character in an echo command?

If I execute this command directly from CLI, I don't have any problem: ~ # apt autoremove 1>$- 2>$- ~ # But if I call it from a script I have some errors: Here is the script: #!/bin/bash -x ...
0
votes
0answers
25 views

Script to compare 2 or more file and dump the difference as output [closed]

I have a file containing the following values on 3 different servers. Server a = file1.txt Server b = file2.txt Server c = file3.txt This is the sample the above file contains file1.txt RoleA is ...
1
vote
0answers
22 views

How do I stop the cat command when it's reading from an named pipe?

I have named pipe that gets data very slowly but endlessly, I want to copy the contents of the named pipe to date formatted files while they arrive. I have something like this do cat /tmp/...
-1
votes
0answers
15 views

Retrieve the raw html locally rendered

I'm trying to get the html text rendered for a webpage for get a image link inside it Since explained by this answers, there's some options for it, as curl $url, wget -O - $url or lynx -source $url ...
1
vote
1answer
29 views

How do I check a git config value in a Bash if/else statement?

I'm trying to read a git config value in a bash script, and conditionally act on it depending on whether it's true or false. I'd expect to be able to do: if [ $(git config --get myvalue) ]; then ...
0
votes
1answer
37 views

How to source only selected lines from a key=value formatted file?

I like to export only NAME and YEAR from ab.txt shown below Below solution works, but there should be a way to do without creating second file b.txt ? Please note there could be spaces in the value. $...
-3
votes
1answer
34 views

using subprocess in python across os platforms [closed]

I am developing a software which includes a python script that runs bash commands using subprocess. Would I be able to run this particular script using windows in the future? I basically am using ...
1
vote
1answer
18 views

Commit message file missing in commit-msg hook

I'm trying to write a commit-msg hook to format my commit messages to wrap at a maximum column width: #!/bin/bash format_max_column_width() { MAX_LINE_LENGTH_CHARS=50 cat "$1" | grep -v "^Bug: |...
0
votes
0answers
13 views

Using several bash variables in SLURM batch script

I want to submit the job efficiently, at first. So, I made a bash job script and meta script like below. First, job.sh #!/bin/sh -l #SBATCH -J test #SBATCH -p bigmem #SBATCH -N 4 #SBATCH --ntasks-...
0
votes
1answer
55 views

query a file based on an input in bash

I would like to query a huge zipped genomic file (dbsnp.gz) with the following columns formatted as follows: chr1 196575462 rs115411599 A G . . RS=115411599;RSPOS=196575462;dbSNPBuildID=...
0
votes
2answers
28 views

-bash: */10: No such file or directory when running cron job

In my current directory, I have a bash script called run_job.sh. This script runs perfectly fine. I'm trying to schedule this script to run every 10 minutes using a cronjob. Here is the code that I ...
0
votes
0answers
18 views

Passing path name with asterisk in bash as argument for python script [duplicate]

I am trying to run a python script with several arguments from bash. Some of the arguments are path names with asterisks as wildcards. However, I've been having some trouble passing the arguments into ...
0
votes
3answers
43 views

Why would one run cat|bash before copying/pasting into a terminal?

I've seen someone running cat|bash before pasting commands from the clipboard into a terminal. bash executes commands in bash I do not know why do we need cat here and |(pipe). What useful effects ...
0
votes
1answer
43 views

Bash - Is there a way to replace a bash command with parameters every time is typed with another parameter?

I am working on a HPC running slurm and CentOS. My workflow software (Nextflow v19.10.0) needs to execute this command squeue --noheader -o %i %t -t all -u username However, I have an error raises ...
0
votes
0answers
11 views

sshpass - connect to multiple servers from txt file? [duplicate]

trying to create small bash script. It will connect to multiple servers (inserted in txt file) and send a command, then output will be in output.txt. Seems it doesn't work, I have something bad. Can ...
0
votes
0answers
11 views

Linking binary path to shell script - Oracle Cloud Infastructure OCI360

I'm new to developing in general and i'm using a tool called OCI360 which gives metadata backup to the cloud tenancy. I'm following the instructions on this link to create a JSON file with all the ...
0
votes
1answer
11 views

Ghostscript On windows leads to Invalid option for -dPDFSETTINGS

To solve my problem here with compressing/down-sizing a PDF file generated by MikTeX on Windows, I am trying this bash script on Cmder as: shrinkpdf.sh in.pdf > out.pdf However I get the error: ...
0
votes
0answers
12 views

mageia: Dual Monitor with single video card and touchscreen and mouse pointer not working right

I am not sure if I am allowed to post this question here. If it needs to be moved, admin can do so. I have a computer with a single video card with dual HDMI, DVI-D and other ports. I use mainly the ...
-1
votes
0answers
35 views

Why is my grep command not able to find the given variable?

I have two text files, a.txt and b.txt. I'm trying to read each line from a.txt and see if that same line exists somewhere in b.txt. script.sh while IFS= read -r line do echo "$line" if ...
0
votes
1answer
20 views

MySQL send error in bash because of space

I am trying few commands in Linux terminal (centos) mysql -u whoisdat_count -pMYPASSWORD -D whoisdat_count -e "CREATE TABLE COUE (`T 001` varchar(255));" it prompts me an error ERROR 1064 (42000) ...
0
votes
2answers
28 views

Bash - Check If given argument exits

I have a separate shell script that runs my docker-compose environment in attached mode or detached if I pass -d or --detach argument. It works fine when I pass this argument (./run-env.sh -d) but it ...
0
votes
0answers
6 views

Can you run a bash script via Azure Logic Apps? [duplicate]

I want to run a .sh script on an on-prem linux machine using Azure Logic Apps, is this possible? I know there are connectors using SFTP-SSH but this only allows you to read/write files.
1
vote
4answers
25 views

checking if a string exists in an array of strings in bash

I know how to compare two string in bash: if [ "$build_type" = "devite" ]; then echo "building'" fi But what I need is to check if "$build_type" is in ["devite", "relite"] so something similar to ...
0
votes
1answer
23 views

In bash how to print all sibling processes of current process

I know the pid of my current process... I am trying to figure out the processes who have same ppid as the pid of current process
0
votes
1answer
20 views

Bash function to alias python command with ipython when no arguments are used

I would like to alias python with ipython only when no arguments are follows so that I can use ipython's shell and its autocompletion feature. For example: #This should start the ipython shell python ...
0
votes
0answers
34 views

I want to represent json data In Column format [duplicate]

[ { "status": 200, "url": "https://url1", "length": 20429 }, { "status": 401, "url": "https://url2", "length": 30890 } ] I have data in this json format.I want to ...
0
votes
0answers
31 views

Delete blank line and Inserting multiple lines with bash & sed - Need help deleting single blank line before match

Attempting to insert host: localhost port: 5432 username: postgres password: postgres into a database.yml file with a bash script, I've been Finally had some success, but now just ...
1
vote
1answer
31 views

Bash while read input issue

An possible way to use while read is: while read server application date; do .. So now i could print only the applications, i understand that. So here comes my question: with my example i know ...
-1
votes
0answers
26 views

Search & replacing strings in all files using sed, without RegEx, on macOS

I'm trying to do the following using sed: Find all files in the packages directory and sub-directories Replace ${CASE_DEFAULT_OWNER} by replacement_string Have this command run on macOS and Linux (...
0
votes
4answers
65 views

awk function to modify several columns with regex in a csv

Goal: I need to modify urls to leave only the number in it (latitude/longitude/id): In a .csv-File i have one "certain Titel in Header". This one i need to find. In the column of this found Titel, i ...
0
votes
2answers
38 views

BASH: Assigning find output to value includes options [closed]

I want to get all files with a specific extention and assign them to a variable. However, when I print the variable, the output includes the options of the find command: annotations=$(find -type f -...
0
votes
1answer
37 views

How yo output file using bash coloring?

I would like to print a MOTD using styled text when an user connects to the server (ubuntu 18.04) using SSH. The only way I found is to print the file by myself because Ubuntu originally only cats ...
-1
votes
1answer
23 views

Print new line as string literal in unix or shell [duplicate]

Hi I have a shell script that has variable="apple banana monkey" I want it to be apple\nbanana\nmonkey But when I try and execute echo $variable | tr ' ' '\n' It results to apple banana monkey ...
0
votes
1answer
25 views

“sed delete” command in bash not always work

With the code: #!/bin/bash echo 'if [ -f /etc/skel/.bashrc ]; then . /etc/skel/.bashrc; fi' >> ~/.bashrc echo 'enable -n echo' >> ~/.bashrc echo "alias cls=\"echo -en '\033c\033[3J'\"" &...
0
votes
1answer
38 views

Run ./configure in a bash and redirect out/err to a file

I need to run ./configure in a bash and redirect out/err to a file, but I got 2 issue : 1) using something like : ARG_COOKIES="--enable-cookies" ARG_ENABLEFILE="--enable-file" cmd=configure "./$cmd" ...
0
votes
1answer
32 views

Bash: grep ip address from udhcpc command output [closed]

I would like to get ip address from udhcpc command out(just after lease of) in bash: udhcpc -i wlan0 -s /etc/udhcpc/sample.script Configuring IP using DHCP udhcpc (v1.18.3) started Sending discover......
-2
votes
0answers
26 views

bash script to find and print info from file [closed]

Program needs to print the whole line of contact info if name is found. We input name to find with inputbox. vardp is name, pavardp is last name, telk is phone number, pastk is email. But it doesn't ...
0
votes
1answer
38 views

Bash Scripting- Switches

#!/bin/bash while getopts "p:" opt; do case ${opt} in p )#print the argument value echo "I like $OPTARG programming" ;; \? ) What if i want to print an error if I don't give '-p'
0
votes
2answers
38 views

How to list all files in all directory in linux using linux cmd

I'm trying to read all the files available in all directories along with complete path, using bash script. Have tried ls -R cmd but it is not listing the files properly. My requirement is to have ...
0
votes
3answers
36 views

redirecting all output to lolcat

I recently found about lolcat. I liked it so much for I want to redirect all my output through lolcat. In the terminal, this can be achieved by ls -lh | lolcat This will output color. If I want ...
-2
votes
5answers
55 views

[: missing `]' error in Unix | shell Script [closed]

I got a [: missing `]' error in my Unix Script memuse=$ free -m if [ $memuse >80] then ...
0
votes
0answers
26 views

Error: command “bash” failed with no error message?

I am using terraform on my Mac system, and terraform apply results with below error Error: command "bash" failed with no error message on ssm.tf line 7, in data "external" "ssm-dynamic-general": ...
-3
votes
1answer
43 views

After installing go and setting my path, I am still getting an error

After installing golang according to the instructions on the golang website, I set the path as it said to by using export PATH=$PATH:/usr/local/go/bin and whenever I use the command $HOME/go it says ...
0
votes
1answer
21 views

GitLab CI encountered an error: command not found: ajv

I got an error in GitLab CI. Before that, I created a question. The problem was solved, but there was a new problem. schema-test.sh file contents: #!/usr/bin/env bash # Test all file ends with ...
-1
votes
5answers
70 views

Replace a specific character at any word's begin and end in bash

I need to remove the hyphen '-' character only when it matches the pattern 'space-[A-Z]' or '[A-Z]-space'. (Assuming all letters are uppercase, and space could be a space, or newline) sample.txt I ...
0
votes
2answers
38 views

bash command to find a specific bit of info in a line of a text file?

I'm running a command that outputs this to /tmp/foo.txt: Title: 01, Length: 01:39:03.734 Chapters: 15, Cells: 17, Audio streams: 04, Subpictures: 04 Title: 02, Length: 00:00:01.000 Chapters: 02, ...
0
votes
1answer
22 views

ROS launchfile only recognized when in the same folder as the launchfile

I can only run roslaunch launchfile.launch when I am in the same folder as the file. If i go back a folder and run roslaunch ~/<directory>/launchfile.launch it says RLException: [...
0
votes
1answer
18 views

How to use nested AWS CLI command syntax?

Below are the two different AWS CLI commands, running on bash: IMAGES_TO_DELETE=$( aws ecr list-images --region $ECR_REGION --repository-name $ECR_REPO --filter "tagStatus=UNTAGGED" --query 'imageIds[...
1
vote
2answers
45 views

How to avoid an error when listing nonexistent files?

I'm grouping files by dates in the filenames and processing them by groups. for m in {01..12}; do for d in {01..31}; do f=`ls ./mydir/2018.${m}.${d}T*.jpg` # process files done done ...