shell中判断变量是否为空

1.变量经过“ ”引号引发来bash

    以下所示,能够获得结果为 is null.net

    

#!/bin/bash

para1=

if[! -n "$para1"]
then
    echo "is null"

else
    echo "not null"

fi

2.直接经过变量判断:code

    以下所示,获得的记过为: is nullblog

#!/bin/bash

para1=

if[!${para1}];then
    echo "is null"
else
    echo "not null"
fi

3.使用test判断get

#!/bin/bash


dmin=
if test -z "$dmin"
then
  echo "dmin is not set!"
else  
  echo "dmin is set !"
fi

4.使用""判断class

#!/bin/bash
dmin=
if [ "$dmin" = "" ]
then
  echo "dmin is not set!"
else  
  echo "dmin is set !"
fi

 

参考资料test

CSDN变量

相关文章
相关标签/搜索