The If Statement in Linux
Updated September 24, 2002
Created November 19, 2001


Autogenerated Site Map
Search this Site!:
Search this site powered by FreeFind

if [ -z "$VARIABLE" ]; then
   echo "Variable is not set"
else
   echo "Varible has value: $VARIABLE";
fi



if [ -n "$VARIABLE" ]; then
   echo "Varible has value: $VARIABLE";
else
   echo "Variable is not set"
fi


OK, here's the nasty one I keep forgetting ('cause usually
it turns out that I don't need to do it this way):
if [[ (5 -gt 2) && (2 -gt 1)]]; then echo hi; fi


Ok, this one keeps getting me a lot too:
[: ==: binary operator expected

The offending code was:
if [ $SUCCESS == true ]; then
the fix was to use only one equal sign:
if [ $SUCCESS = true ]; then


Search this Site!:
Search this site powered by FreeFind

Homepage: http://www.cpqlinux.com
Site Map: http://www.cpqlinux.com/sitemap.html