I am trying to run the following shell script which is supposed to check if a string is neither space nor empty. However, I am getting the same output for all the 3 mentioned strings. I have tried using the "[[" syntax as well but to no avail.
Here is my code:
str="Hello World"
str2=" "
str3=""
if [ ! -z "$str" -a "$str"!=" " ]; then
echo "Str is not null or space"
fi
if [ ! -z "$str2" -a "$str2"!=" " ]; then
echo "Str2 is not null or space"
fi
if [ ! -z "$str3" -a "$str3"!=" " ]; then
echo "Str3 is not null or space"
fi
I am getting the following output:
# ./checkCond.sh
Str is not null or space
Str2 is not null or space
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…