Reputation: 41
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?
Upvotes: 4
Views: 422
Reputation: 531748
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
Upvotes: 5