I've got a few csh scripts where I need to check that certain environment variables are set before I start doing stuff, so I do this sort of thing:
if ! $?STATE then
echo "Need to set STATE"
exit 1
endif
if ! $?DEST then
echo "Need to set DEST"
exit 1
endif
which is a lot of typing. Is there a more elegant idiom for checking whether or not an environment variable is already set?
Notes:
- This question is quite similar, but specifically asks about solutions in bash.
- I'm not looking for people to advise me to stay away from csh because it's cursed, scary, or bash is better. I'm specifically interested in a more elegant solution than what I'm using now.