0

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:-}

Shamshad Alam
  • 1,684
  • 3
  • 19
  • 31
  • 1
    @TomFenech This is used to avoid fatal errors when you have called `set -u` before – xhienne Mar 24 '17 at 12:06
  • @xhienne that's interesting, thanks. I think that if you made your comment into an answer, this could become a separate question regard the empty default expansion, which would be an improvement. – Tom Fenech Mar 24 '17 at 13:12

1 Answers1

1

${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

Community
  • 1
  • 1
John Bupit
  • 10,406
  • 8
  • 39
  • 75