linux++:Linux - sh 脚本基础

1、判断一个变量是否为空 的方法

1、变量通过" "引号引起来
#!/bin/sh
para1=
if [ ! -n "$para1" ]; then
  echo "IS NULL"
else
  echo "NOT NULL"
fi 

----------------------------
2、直接通过变量判断
#!/bin/sh
para1=
if [ ! $para1 ]; then
  echo "IS NULL"
else
  echo "NOT NULL"
fi 

-----------------------------
3、使用test判断
#!/bin/sh
dmin=
if test -z "$dmin"
then
  echo "dmin is not set!"
else  
  echo "dmin is set !"
fi

---------------------------------
4、使用""判断
#!/bin/sh 
dmin=
if [ "$dmin" = "" ]
then
  echo "dmin is not set!"
else  
  echo "dmin is set !"
fi

 

posted @ 2020-05-19 11:08  coding++  阅读(270)  评论(0编辑  收藏  举报