Sui

shell脚本-判断变量是否为空

字数统计: 87阅读时长: 1 min
2021/02/18 Share

shell脚本-判断变量是否为空

第一种方式

1
2
3
4
if [ -n $1 ]
then
echo '$1 is null1'
fi

如果$1为,则会返回true

第二种方式

1
2
3
4
if [ "" = "$1" ]
then
echo '$1 is null2'
fi

第三种方式

1
2
3
4
if [ ! $1 ]
then
echo '$1 is null3'
fi

第四种方式

1
2
3
4
if test -z $1
then
echo '$1 is null4'
fi
CATALOG
  1. 1. shell脚本-判断变量是否为空