Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [bash]

Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

0
votes
1answer
17 views

Using bash script to pipe breakpoints to debugger prompt

I am using bash to write a script to make it easier to set breakpoints. I am trying to see if I can use echo and pipe to send set breakpoints commands to the java debugger jdb. The command I have ...
7
votes
3answers
247 views

How do I add a variable to this curl command?

I have a curl command that sends a string of text to the server and I've been trying to figure out how to either have the string of text come from a file or from a bash variable. The command looks ...
-2
votes
1answer
67 views

Running a pipelin in linux [closed]

I have this script #!/bin/bash module load bedtools/2.21.0 bamfiles=( /temp/hgig/fi1d18/1672_WTSI-COLO_023_1pre/mapped_sample/HUMAN_1000Genomes_hs37d5_RNA_seq_WTSI-COLO_023_1pre.dupmarked.bam /temp/...
0
votes
1answer
56 views

Trying to export a path from inside a bash script [duplicate]

I am trying to put my whole environment set up into a single bash file. I am only hitting one issue. When I try to export a new path from inside the file it is not setting the path in the environment ...
0
votes
1answer
29 views

git pre-commit script

The goal is to exit from the script with a non-zero exit code when committing package-lock.json with no associated changes to package.json being committed. #!/bin/bash # exits with 1 if there were ...
1
vote
3answers
60 views

Executing bash scripts simultaneously

I run several bash scripts in separate terminal windows (tabs). I want to mix them to run in the same window and provide mix outputs. I just need to initiate all scripts independently in the same ...
2
votes
4answers
82 views

Removing (possibly nested) text quotes in command line

I need to parse large amounts text in command line and replace all (possibly nested) text quotes with spaces. Quotes are marked with specific syntax: [quote=username]quoted text[/quote]. Example ...
0
votes
1answer
16 views

Printf format error for number

After some greping and seding I manage to get a value from a csv cell and assign it to a variable (DBR). Here come some odd findings echo $DBR echo "$DBR", printf "%f" $DBR output: 9.1 ,.1 : ...
4
votes
3answers
391 views

Indirectly access environment variable [duplicate]

Given I have in a bash script ev=USER How can I get the environment variable value for $USER using ev? Tried naively doing: echo ${"$"$ev} which results in bad substitution. I'd expect to get ...
2
votes
1answer
45 views

When and where $- options are set?

I am searching for the initial setting of the $- variable. From which file and at which point it gets initialized?
1
vote
2answers
110 views

making bind -p human readable

The man page for bind appears not to link to a syntax explanation, so while attempting to convert bind -p into human readable format I can filter out the garbage from 483 down to 109, but then am only ...
0
votes
1answer
25 views

How to clear the screen from command line in GAP

Normally I can clear the screen with ctrl-L but while running GAP, ctr-l just displays the last command entered.
4
votes
3answers
330 views

How to escape the null character in here-document?(bash and/or dash)

I want to perform shuf --zero-terminated on multi-line strings with here-document.
0
votes
1answer
14 views

Bash's history behavior when using ! and ! :p for old commands changed

Suddenly my bash history behavior changed. When I'm either calling an old command using !num (where num is the number of the commmand as seen in history) or displaying the command (without running it) ...
2
votes
4answers
313 views

How to count the characters of jar files by wc

Under the folder /usr/hdp/2.6.4.0-91/tez_hive2/lib/ We have .jar files as the following $ ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" async-http-client-1.8.16.jar azure-data-lake-store-sdk-...
0
votes
0answers
58 views

Remote ssh script execution with EOI or EOSSH adding dots in front of commands

Here the first block was running, second block was not. And the problem was EOI considers spaces as dots, I think. But, it does not consider tab as dot. Making no indentation worked for me. But is ...
0
votes
3answers
55 views

How to break a long string into multiple lines assigned to a variable in linux bash script

I am working towards writing a bash script that contains a variable with a long string value. When I split the string into multiple lines it is throwing error. How to split the string into multiple ...
0
votes
1answer
39 views

Why is program not found in PATH [duplicate]

I've installed ipython inside virtualenv on my macOS. My PATH environment variable also shows virtualenv path to be at the beginning. which command also shows that ipython at the correct location. ...
0
votes
0answers
28 views

To get super user name in shell script [duplicate]

I am having a bash shell script (eg - test.sh). In this shell script I have below statements- sudo su - dbmanage echo `whoami` >>$LOGFILE when I execute the script by login with my account "...
0
votes
0answers
25 views

kill gnu parallel inside a bash function

I am using gnu parallel in a subshell function, e.g., func()( parallel --will-cite sleep ::: 60 ) upon sending SIGTERM to the function I want parallel to be killed too. But I get $ func & [...
1
vote
5answers
45 views

Running a loop from second line of a file in a bash script

I want to use the below file content as an input of for loop my script. As from second line we have id's which will be used to fetch content from db. cat abc.txt id 27 27 27 27 23
-2
votes
1answer
47 views

Why does echo -e “\n” give me two blank lines instead of one?

Let's say there's a line "aaaa" in file.txt, and I want to add ONLY ONE blank line after it, and then add a line of text after the blank line. I did: echo -e "\n" >> file.txt echo "bbbb" >> file.txt ...
0
votes
2answers
51 views

Check via shell-script if git repository's master branch is behind origin

I'm currently writing a bash script to remind me to rebase git repos when the local master branch is found to be behind origin/master. So far I have come up with the following, but $? always returns ...
0
votes
2answers
43 views

CLI run multiple commands and close terminal

I want to run the following commands and close the terminal: mysqldump -udatabase -pdatabase database > db.sql && zip db.sql.zip db.sql && rm db.sql && mv db.sql.zip /var/...
0
votes
2answers
37 views

Bash Shell takes variable amount of time to load

I use bash on Ubuntu 18.04. I have added a lot of functions and a lot of scripts are sourced in my bashrc. I am able to time the total time it takes to load my terminal, sometimes it takes 0.9 seconds ...
3
votes
1answer
168 views

using 'echo' & 'printf' in bash function calls

I have a simple shell function call and I'm using echo and printf commands to print the parameter I'm passing. I have noticed the following: echo is printing the output printf is not printing the ...
0
votes
1answer
41 views

Bash regex and IFS split

I have the following problem: I want to extract text that is inside brackets from a string (with or without the brackets). My string looks like this: STR="[1] [2][345] [678 9] foo bar" I initially ...
12
votes
2answers
773 views

What is the data structure of $@ in shell?

We usually use $@ to represent all of argument except $0. However, I don't know what data structure $@ is. Why it behave differently with $* when including in double quote, could anyone give me a ...
1
vote
1answer
52 views

Bash ` &` behaviour inconsistent when there's a loop at the end of the script

When I start up Linux Mint 19, I like to launch a few things. So I've been using a script (./get-to-work) in a MATE Terminal window to launch them all at once: chromium-browser --start-maximized &...
2
votes
1answer
36 views

How does cd's “-@” parameter work?

bash's man page (and help cd) mentions that cd supports a -@ parameter ("on systems that support it") to "present a file with extended attributes as a directory containing the file attributes" Is ...
-1
votes
1answer
53 views

read variable from file is out of alignment and extra line

#!/bin/bash FILES=/tmp/files.txt FIELDNAME=/tmp/fieldname.txt num=$(wc -l < $FIELDNAME) #to read fieldname.txt content FILE1=$1 cat $FILE1 > FILE2 value=$(<FILE2) #to create empty lines ...
0
votes
0answers
28 views

Parallel ssh commands forking in background but keeping ssh open

I'm trying to set up a script that performs commands on multiple ssh hosts (Ubuntu 16/18, CentOS, SuSE) at once. It is working fine with different commands, unless I have to execute a process on the ...
1
vote
2answers
70 views

How convert bash output to JSON with key {#PROCNAME}?

I try get JSON with top 5 process by memory. This JSON i want send to Zabbix and draw top 5 process by memory. I get top 5 process by memory by command: ps axho comm --sort -rss | head -5 node ...
0
votes
1answer
34 views

Implement a script in Solaris when usage in all filesys >90% & send a mail i dont know how to send mail from script

Script in Solaris when usage in all filesystem >90% & send a mail i don't know how to send mail from script #!/bin/bash # Outputs alert if filesystem is above 90% { for fs in $(df -hk | ...
0
votes
0answers
17 views

How can I ensure some shell or bash option is enabled or disabled and later on restore it if I have changed it? [duplicate]

Sometimes I want to do something which requires some shell or bash option enabled or disabled. For example, https://unix.stackexchange.com/a/108520/674 So I could first change the shell or bash ...
43
votes
1answer
2k views

What is the difference between “…”, '…', $'…', and $“…” quotes?

Sometimes I see scripts use all of these different ways of quoting some text: "...", '...', $'...', and $"...". Why are there so many different kinds of quote being used? Do they behave differently ...
1
vote
2answers
78 views

How to recursively copy only the files from folders and subfolders?

Under /home folder we have many subfolders, as the following: /home/user1 /home/user2/user_sub_2 /home/user3/user_sub_3/info_sub /home/user4/INFO_FOLDER We want to copy all the files under /home, ...
0
votes
2answers
42 views

append values under element in json

the following parameter include list values ( list of machines ) for example echo $list_of_machine worker01.sys645.com worker02.sys645.com worker03.sys645.com worker04.sys645.com worker05.sys645....
0
votes
2answers
54 views

Recursive conversion of jpeg files

I use this commandline to convert jpegs to pdfs inside a folder. for f in *.jpg; do echo "Converting $f"; convert "$f" "$(basename "$f" .jpg).pdf"; done However, I would like to convert all .jpg ...
9
votes
1answer
536 views

Is there any advantage in specifying './' in a for loop using a glob?

I was under the impression it could be safer to use ./*.fastq when searching for files ending with .fastq. For example, ./ would prevent capturing the file .fastq. This is obviously wrong, as shown in ...
1
vote
1answer
39 views

Documentation on bash completion

I've been unable to find complete documentation for the complete and compgen bash builtin commands. I'm on a Macintosh and help complete produces complete: complete [-abcdefgjksuv] [-pr] [-o option] ...
3
votes
1answer
52 views

Escape parameters for positional arguments

I have external bash script which is called by system with bash to compile golang sources, and I'm able to configure some varialbes. This script is a golang-build.eclass. The build function in this ...
-1
votes
4answers
45 views

I want to find only the duplicated words and count them, but to ignore that unique words (non-duplicated words)

Here is the command like: echo "zebra ant spider spider ant zebra ant dog shark" | xargs -n1 | sort | uniq -c | xargs Result: 3 ant 1 dog 1 shark 2 spider 2 zebra I want to ignore the unique words ...
3
votes
1answer
207 views

Process substitution inside a subshell to set a variable

I'm trying to run a script remotely and use its standard output to populate a variable. I'm doing this to avoid temporary files. Here's the pattern I'm trying: var=$(bash <(curl -fsSkL http://...
1
vote
1answer
37 views

ssh bash completion : sed: -e expression #1, char 97: invalid reference \2 on `s' command's RHS

I'm using Ubuntu 14.04.5 LTS. The ssh bash completion on any Host of the file ~/.ssh/config does not work : $ ssh b2sed: -e expression #1, char 97: invalid reference \2 on `s' command's RHS The ...
0
votes
1answer
48 views

Using interactive's shell history expansion inside a script

I have the following Bash script set -o histexpand set -o history pwd lc="!!" which, when I run it in an interactive shell, prints /home/user lc="pwd" I'd like to, instead of getting lc=pwd, get ...
0
votes
1answer
51 views

Script to kill -2 the PID and restart the process

I'm facing problem while running a script 'restart.sh'. Its main objective is to kill a process by id, and restart the process again. The process name has 'DND' as below $ ps -ef | grep DND root ...
1
vote
1answer
41 views

unable to run bash script from bash script

I've created a script that has to be executed on boot and has to run another script (which sets some variables) before executing other commands. After writing the script, I've successfully executed ...
0
votes
1answer
49 views

How can I use the watch command to run a bash script and monitor output file? [closed]

So I have a bash script "example.sh" that will write into an output file, say "tmp_output.txt". (It will empty the file and rewrite if data already exists in it) How can I use the watch command so ...
2
votes
1answer
35 views

History expansion in scripts [duplicate]

I have the following Bash script case $- in (*H*) echo enabled ;; (*) echo disabled ;; esac set -H case $- in (*H*) echo enabled ;; (*) echo disabled ;; esac pwd last_command="!!" echo $last_command ...