<分区>
我将以下行作为更大的 bash 脚本的一部分:
if [ `packages/TinySVM-0.09/bin/svm_learn 2>&1| grep TinySVM | wc -l | cut -c0-7 | sed 's/^ *//g'` -eq 1 ]
运行脚本后,我得到:
./install.sh: line 219: [: -eq: unary operator expected
第 219 行是上面的行。有任何修复建议吗?
<分区>
我将以下行作为更大的 bash 脚本的一部分:
if [ `packages/TinySVM-0.09/bin/svm_learn 2>&1| grep TinySVM | wc -l | cut -c0-7 | sed 's/^ *//g'` -eq 1 ]
运行脚本后,我得到:
./install.sh: line 219: [: -eq: unary operator expected
第 219 行是上面的行。有任何修复建议吗?
最佳答案
您可以在没有任何额外语法的情况下运行您的命令。例如,下面检查 grep 的退出代码,以确定正则表达式是否匹配:
if ! grep -q "$word" /usr/share/dict/words
then
echo "Word $word is not valid word!"
fi
关于bash - bash脚本if语句里面的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5276393/