Shell 命令查看变量值是否为空

Using below code to check whether the var value is empty or not:

if [ -z "$var" ]
then
      echo "\$var is empty"
else
      echo "\$var is NOT empty"
fi

Or direcly check whether the var is not empty

 

if [ ! -z "$var" ]; then
    echo "\$var is NOT empty"
fi

 

你可能感兴趣的:(Shell)