Reputation: 543
I'm following this tutorial on transformation of variables.
If I have the following:
echo ${TEST:-test} #TEST is undefined, 'test' is printed and TEST is still undefined.
echo ${FOO:?"some text"} #"some text" is printed and FOO is still undefined.
What is the difference between the ':-'
and the ':?'
above?
Upvotes: 0
Views: 40
Reputation: 44394
These are testing shortcuts:
echo ${TEST:-test}
If $TEST
exists then its value will be used, otherwise the value of $test
will be used. If you want TEST
to be set then you probably need:
echo ${TEST:=test}
Next one:
echo ${FOO:?"some text"}
If $FOO
is set then use its value, else output to stderr
the error message "some text" (default is "parameter null or not set").
Upvotes: 1