Take the 2-minute tour ×  What is the best way to make sure that
all the environment variables I need for my script have been
set? Currently, I have multiple if-statements which is not very
neat:  if [ -z "$VAR1" ]     echo VAR1 not set  if [ -z "$VAR2"
]     echo VAR2 not set  if [ -z "$VAR3" ]     echo VAR3 not set
Is there a better way?  share|improve this question add comment
4 Answers  up vote 3 down vote accepted  You can use
indirection:  vars="FOO BAR" for var in $vars         echo
"Variable ${var} is empty" ||         echo "The value of
variable ${var} is ${!var}" share|improve this answer Exactly
what i meant! Great!!+1 –  vpram86 Sep 9 '09 at 9:23 Note that
this tests if empty, not if it is set –  AlberT Sep 9 '09 at
9:39 add comment  Use a for loop in (set of variables u want).
Won't that work?  share|improve this answer Thanks! I wont
suggest this in future. I was also not sure. Just asked :) – 
vpram86 Sep 9 '09 at 9:12 Wow!! Then will this work?? –  vpram86
Sep 9 '09 at 9:12 plz edit your ans