在shell脚本中获取整数表达式预期错误?

时间:2013-12-18 12:08:57

标签: bash

#!/bin/bash

a= vmquery -b -pn Scratch |grep -i ACS |grep -iw hcart3|wc -l

if [ "$a" -lt 20 ] ; then
                mailx -s "BSPRD267 Scratch Count" my@email
        else
                echo "Scratch count is $a"
fi

获取错误消息如下: -

  

./ scratch.sh:line 3:[::期望整数表达式

1 个答案:

答案 0 :(得分:1)

要评估命令并将结果存储到变量中,您需要执行var=$(command)。在你的情况下:

a=$(vmquery -b -pn Scratch |grep -i ACS |grep -iw hcart3|wc -l)