What does expression `${ID:-}` do in shell script? [duplicate] - shell

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

Related

bash script, want to use '$' without it looking for a variable [duplicate]

This question already has answers here:
Interpolating variables which contain '$' in a bash script
(1 answer)
Difference between single and double quotes in Bash
(7 answers)
Closed 2 years ago.
I need to write a cron job, to send an mqtt message to "homie/$HOSTNAME/$state".
In the case of $HOSTNAME - it needs to use the env variable, but $state - it must use as is.
How would I add "homie/$HOSTNAME/$state" without bash thinking the $state is a variable as well?

Need help understanding this bash variable: "${rvm_path-$HOME/.rvm}/scripts/rvm" [duplicate]

This question already has an answer here:
variable expansion in curly braces
(1 answer)
Closed 6 years ago.
I was reading the answer here:
How to change rvm install location
it keeps referencing the below variable:
"${rvm_path-$HOME/.rvm}/scripts/rvm"
I know that I have $rvm_path and $HOME set, but I don't understand what the whole excerpt means.
This is a parameter expansion.
If a variable named rvm_path exists, it is expanded. Otherwise, $HOME/.rvm is used instead. Regardless, /scripts/rvm is appended to the result.

What is meant by :- this symbol in unix shell scripting [duplicate]

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

How can i get the value from a file using bash? [duplicate]

This question already has answers here:
Shell command to retrieve specific value using pattern
(3 answers)
Closed 8 years ago.
I have file test.txt contains the following
AA=testing
BB=help
CC=hello
How can i make a bash script that will get each value and assign to a new variable?
#!/bin/bash
var1=testing
var2=help
var3=hello
thanks for the help
First of all a = value is not correct syntax in shell. In shell the spaces are important.
When you have a valid file, you can use the eval function to evaluate that file as a string, or simply source it.

Esoteric shell script syntax [duplicate]

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

Resources