shell 字符串

-z“字符串”   :若字符串长度为0 则为真    -z  zero

【-z "$myvar"】

[root@web02 ~]# [ ! -z "liwm" ]&& echo 1 ||echo 0
1

-n“字符串”   若字符串长度不为0则为真  -n   no zero 

【-n "$myvar"】

[root@web02 ~]# [ -n "liwm" ]&& echo 1 ||echo 0
1

[root@web02 ~]# [ -n "" ]&& echo 1 ||echo 0
0

等号两边需要空格

[root@web02 ~]# sed -n '30,31p' /etc/init.d/network
# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 6

[root@web02 ~]# vim /etc/init.d/nfs

# Source networking configuration.
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network

# Check for and source configuration file otherwise set defaults
[ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs

# Remote quota server
[ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`

原文地址:https://www.cnblogs.com/liweiming/p/9947886.html