Shell Script : How to check if variable is null or no
Try following, you should change from -z
to -n
as follows and add $
to your variable too.
if [[ -n "$list_Data" ]]
then
echo "not Empty"
else
echo "empty"
fi
Explanation: From man test
page as follows(It checks if a variable is having any value or not. If it has any value then condition is TRUE, if not then it is FALSE.)
-n STRING the length of STRING is nonzero
if [[ -z "$list_Data" ]]
then
echo "Empty"
else
echo "Not empty"
fi
Try it like this. (Added $
and switched cases.)