在shell 中判断变量为null
方法一:
if [ $x ];then echo 'not null' else echo 'is null' fi
方法二:
if [ -z "$x" ]; echo 'is null' else echo 'not null' fi
Shell中判断变量是否为空
本文介绍了两种在Shell脚本中判断变量是否为空的方法。方法一使用if [$x]进行判断,方法二采用if [-z$x]来检查变量$x是否为空。这两种方法可以帮助开发者在脚本中有效地处理空变量的情况。
在shell 中判断变量为null
方法一:
if [ $x ];then echo 'not null' else echo 'is null' fi
方法二:
if [ -z "$x" ]; echo 'is null' else echo 'not null' fi

被折叠的 条评论
为什么被折叠?