How to check for null or empty stri

July 19, 2007 at 20:44:00
Specs: NA, NA

I need to check for value not equal (<>) to 21 and not equal empty or null values.

Please modify this script

if [ $VALUE -ne "21" ]
then
echo "$VALUE,$BSC_NAME,$BSC_ID" > $OUT_FILE/power_up.out
end if

thanks


Nimi


See More: How to check for null or empty stri

Report •


#1
July 20, 2007 at 07:32:57

Since $VALUE could evaluate to a null string, it needs to be double-quoted for syntactical place-holding.

The code below checks for either null value or an exact string check for 21 which can be placed in quotes if desired.  It would test false for a VALUE of 021.

if [ -z "$VALUE" -o "$VALUE" = 21 ] ; then
   echo 'VALUE is null or exact string "21"'
fi

The code below checks for either null value or a numerical check for 21. While the numeric test has the advantage (if desired) of testing positive for numerical equivalents such as +0000021, this code will throw an error message if $VALUE is non-integers.

if [ -z "$VALUE" -o "$VALUE" -eq 21 ] ; then
   echo 'VALUE is null or numerical 21'
fi


Report •
Related Solutions


Ask Question