This question already has answers here:
Usage of :- (colon dash) in bash
(2 answers)
Closed 5 years ago.
Can anyone please tell me what is mean by :- this symbol in Unix shell scripting
while [ ${runq:-$SLOTS} -ge $SLOTS ] in the given example
This is a simple way to provide a default value using an expansion. See http://wiki.bash-hackers.org/syntax/pe#use_a_default_value for more information.
There are also answers to similar questions on stackoverflow like Read a variable in bash with a default value
Related
This question already has answers here:
Dynamic variable names in Bash
(19 answers)
How to use a variable's value as another variable's name in bash [duplicate]
(6 answers)
Bash - variable variables [duplicate]
(4 answers)
Closed 2 years ago.
I recently started bash scripting and got stuck with a very basic usecase, searched stackoverflow/google but couldn't find a way to achieve what I am trying to do.
I have a script color.sh
#!/bin/bash
Apple="Red"
Orange="Orange"
Banana="Yello"
echo $$1
What I am trying to achieve is print the color of fruit and accept fruit from command line. The output I want is
./color.sh Apple -> Red, but what I get is some random number which I think is process Id.
This question already has answers here:
What is the difference between $(command) and `command` in shell programming?
(6 answers)
What is the benefit of using $() instead of backticks in shell scripts? [duplicate]
(9 answers)
Closed 3 years ago.
In Unix we have 2 ways to execute a command and capture its output in a variable:
1.)
x=`wc-l`
2.)
x=$(wc -l)
Can anyone help me understand the basic difference between the two, and when to use which syntax.
This question already has answers here:
Usage of :- (colon dash) in bash
(2 answers)
Closed 5 years ago.
I encountered ${ID:-} in a shell script, but I am not sure what does this expression exactly do.
After a bit of googling I found that ${var} and $var are both the same. Such expression is useful when we want to expand expression like ${foo}bar.
However I didn't find any source explaining expression like ${ID:-}.
I would like to know about expression ${ID:-}
${variable:-default_value} is used to return the default value, if the variable is not set.
Related: Assigning default values to shell variables with a single command in bash
This question already has answers here:
What are the special dollar sign shell variables?
(4 answers)
Closed 8 years ago.
I am trying to understand a script that was written a few years ago by someone that is no longer available here. The script references $? a few times. What is this?
P.S. Google couldn't help since it seems to strip the $? from the search term
You really should read the GNU bash manual. $? is a special parameter which
expands to the exit status of the most recently executed foreground pipeline.
Read also the advanced bash scripting guide.
This question already has answers here:
Trouble understanding parameter substitution in a script
(1 answer)
Usage of :- (colon dash) in bash
(2 answers)
Closed 9 years ago.
I've found this in a shell script that I use and I'm having trouble finding a formal description/definition of this syntax:
ACTION=${1:-update}
I'm assuming that if $1 variable does not exist (no command line arguments) then "-update" is used.
It's not esoteric. It's POSIX, and even Bourne. In every shell manpage ever. man bash or man ksh. The assumption is mostly right, if the parameter 1 is unset or empty string, then expand the alternate.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02