Bash: if statements
Submitted by jacob on Wed, 04/30/2008 - 8:45pmAn if statement in shell scripting looks something like this:
if [ "$VAR" = 1 ]
then
#do something
elif [ "$VAR" = 2 ]
then
#do something else
else
#do something by default
fi
Notice we're quoting the variable to protect from shell expansion.
There are a variety of file tests one can use:
if [ -e /tmp/test.file ]
then
#do something
elif [ -d "$VAR" ]
then
#do something else
else
#another default action
fi