[:- eq: 预期的一条机构

#!/bin/bash 
export PROCNAME=test
export TABLE_ID=0

if [ ${TABLE_ID} -eq "" ]; then
echo hello
fi


以上抛出错误:

[:-eq: 预期的一条机构

如何用双方括号固定它
[[ ${TABLE_ID} -eq "" ]]

.
已邀请:

三叔

赞同来自:

检查字符串的平等
=

.


#!/bin/bash 
export PROCNAME=test
export TABLE_ID=0

if [ "${TABLE_ID}" = "" ]; then
echo hello
fi

帅驴

赞同来自:

您可以使用
-z

, 要检查变量是否为空:


if [ -z "$variable" ]; then
...
fi


经过
man test

:


-z STRING
the length of STRING is zero


见示例:


$ r="roar"
$ [ -z "$r" ] && echo "empty" || echo "not empty"
not empty
$ r=""
$ [ -z "$r" ] && echo "empty" || echo "not empty"
empty

窦买办

赞同来自:

#!/bin/bash 
export PROCNAME=test
export TABLE_ID=0

[ -z ${TABLE_ID} ] && echo hello

要回复问题请先登录注册