什么是这个特定的shell脚本语句validation?

我不是一个好的Shell脚本专家。 有人能帮助我理解和解释这个说法[ ! -z ${TRUE:-} ] && [ ${TRUE:-} == 'true' ] && [ ! -z ${TRUE:-} ] && [ ${TRUE:-} == 'true' ] &&从下面的代码片段。 这个特定的声明是做什么和/或被validation的?

但是,能够理解这个语句: TRUE=$($JBOSS_TWIDDLE get jboss.system:type=Server Started |grep Started |cut -d"=" -f2) 。 这基本上调用JBoss的JMX命令行工具来检查服务器的启动状态。

代码片段:

 while [ $i -lt 180 ]; do TRUE=$($JBOSS_TWIDDLE get jboss.system:type=Server Started |grep Started |cut -d"=" -f2) [ ! -z ${TRUE:-} ] && [ ${TRUE:-} == 'true' ] && { echo "The $JBOSS_NAME server is up and running." return } 

正如@ drew-khoury和@ramruma指出的那样, [ -z ...testing是多余的。

使用TRUE作为variables的名字只会增加混淆。

代码片段试图回答的实际问题是:did twiddle.sh print Started=true ? 或者在shell里说:

 jboss_is_started() { ($JBOSS_TWIDDLE get jboss.system:type=Server Started | grep 'Started=true' | read) } 

grep ... | read 如果grep成功, grep ... | read结构将返回true,同时删除输出。

 if jboss_is_started; then echo "The $JBOSS_NAME server is up and running." return fi 

如果使用双引号,则不需要针对$ TRUE为空的复杂预防措施。

 [ "$TRUE" = 'true' ] 

-ztesting$ TRUE是否为空,以及: – 如果未设置,则不进行replace。 这是没有必要的。 也许这是对一个过分规定的编码标准的抗议。