Timeline for Test if multiple variables are set
Current License: CC BY-SA 3.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 27, 2014 at 11:58 | comment | added | Jasper |
set -u could be used as well I think, but it is not as flexible as proper parameter expansion (see my updated question). And with set -u I'd have to make a dummy-access to all target variables if I want to check their presence in one place.
|
|
| Mar 26, 2014 at 13:23 | comment | added | Hauke Laging | @n.st This doesn't make any sense for the OP as he does not want a protection against accessing unset variables (BTW: a set but empty variable would cause the same error but nor react to your "protection"). He wants a run time check whether a variable is unset / empty. Your suggestion may be useful as a general development help but does not solve the OP's problem. | |
| Mar 26, 2014 at 8:02 | comment | added | mikeserv | @n.st I disagree - null can be just as useful a value as not null if you plan for it. | |
| Mar 25, 2014 at 18:55 | comment | added | n.st |
@HaukeLaging I don't quite follow you — set -u prevents exactly the kind of error the OP is trying to avoid and (in contrary to all other solutions) isn't limited to a specific set of variables. It is in fact a useful precaution for almost all shell scripts to have them fail safely instead of doing unexpected things when a variable is unset. This article is a handy reference on the topic.
|
|
| Mar 25, 2014 at 18:39 | comment | added | Hauke Laging | And in your opinion this makes which sense for run time checks? | |
| Mar 25, 2014 at 16:49 | history | answered | n.st | CC BY-SA 3.0 |