Can anyone please tell me what is mean by :-
this symbol in Unix shell scripting
while [ ${runq:-$SLOTS} -ge $SLOTS ]
in the given example
It's a parameter expansion, it means if the third argument is null or unset, replace it with what's after :- $ x= $ echo ${x:-1} 1 $ echo $x $
# Comment or Trim Strings. Most often, you use the hash or number sign (#) to tell the shell what follows is a comment, and it should not act on it. You can use it in shell scripts and—less usefully—on the command line.
The 1 denotes standard output (stdout). The 2 denotes standard error (stderr). So 2>&1 says to send standard error to where ever standard output is being redirected as well.
It's the first special case of parameter substitution in man bash : ${parameter:-word} Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With