Search This Blog

Thursday, May 17, 2007

Shell scripting: Testing empty variables

$V="xNotEmpty"

if [ x$V = "xNotEmpty" ]
then
       echo "\$V not empty"
else
       echo"\$V is empty"
fi

Or:

if [ "$V" = "" ]
then
      echo "\$V is empty
fi

No comments: