-2

I have an expression like this in a bash file:

MY_NEW_VAR="path/${MY_VARIABLE:?}"

What does :? operator mean?

user1552545
  • 1,233
  • 3
  • 15
  • 33
  • 2
    [Shell Parameter Expansion](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html). – PesaThe Feb 06 '18 at 13:26
  • 3
    Possible duplicate of [What is the meaning of a question mark in bash variable parameter expansion as in ${var?}?](https://stackoverflow.com/questions/8889302/what-is-the-meaning-of-a-question-mark-in-bash-variable-parameter-expansion-as-i) – Benjamin W. Feb 06 '18 at 14:31

1 Answers1

8

If $MY_VARIABLE exists and isn't null, return it's value.
If it doesn't exist, or is null, print the error message you're able to set.

MY_NEW_VAR='path/${MY_VARIABLE:?"error message"}'

If no error message is given, it return parameter null or not set.

roest
  • 356
  • 1
  • 9