I have some bash scripts which I am going through and I find that the code uses following construct for many variables:
ID1="{ID2:?}"
. ${PATH1:?}/file1
Can someone please help me in understanding what ?
does in this?
In this context, it raises an error if the parameter is unset or null. Usually, you see a custom error message following the ?
, but in the absence of one, a generic error message is printed instead.
$ unset id2
$ id1=${id2:?}
bash: id2: parameter null or not set
$ id1=${id2:?nope}
bash: id2: nope
$ id2=9
$ id1=${id2:?}
$ echo $id1
9
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