shell判断一个变量是否为空方法总结
shell中如何判断一个变量是否为空
shell编程中,对参数的错误检查项中,包含了变量是否赋值(即一个变量是否为空),判断变量为空方法如下:
1.变量通过" "引号引起来
#!/bin/sh para1= if [ ! -n "$para1" ]; then echo "IS NULL" else echo "NOT NULL" fi
【输出结果】"IS NULL"
2.直接通过变量判断
#!/bin/sh para1= if [ ! $para1 ]; then echo "IS NULL" else echo "NOT NULL" fi
【输出结果】"IS NULL"
3.使用test判断
#!/bin/sh dmin= if test -z "$dmin" then echo "dmin is not set!" else echo "dmin is set !" fi
【输出结果】"dmin is not set!"
4.使用""判断
#!/bin/sh dmin= if [ "$dmin" = "" ] then echo "dmin is not set!" else echo "dmin is set !" fi
【输出结果】"dmin is not set!"
相关推荐
tianhuak 2020-11-24
woaimeinuo 2020-10-21
touchfuture 2020-09-16
laisean 2020-11-11
Julyth 2020-10-16
laisean 2020-09-27
flycappuccino 2020-09-27
liguojia 2020-09-27
huha 2020-10-16
lianshaohua 2020-09-23
zhangjie 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
CARBON 2020-10-20
彼岸随笔 2020-10-20
lianshaohua 2020-10-20