Let assume I have something like below:
eval link='/var/lib/${XYZ}/test' # string from another text file
XYZ is just for the the example and it could be anything like below:
eval link='/var/lib/${MY_OWN_VAR}/test' # single quote here not double quotes
eval link='/var/lib/${WHAT_EVER}/test'
Is it possible to error out if XYZ
is not set? or is there any other way to figure out if XYZ
is set or not?
I have looked at this, but the assumption there is that you know the variable name. In my case I have no control over what would be in the string to be evaluated.
UPDATE
To be clear, all the strings that needs to be evaluated are from a text file. basically a program reads a text file and outputs the evaluated strings.
All I am trying here is to figure out a way to gracefully catch "unbound variable" error while evaluating any string. basically what set -u
does but gracefully.