原文:Shell脚本报错unary operator expected

在匹配字符串时用了类似这样的语句 if timeofday yes then echo Goodmorning exit 报错的原因是:如果变量timeofday的值为空,那么就if语句就变成了if yes ,这不是一个合法的条件。为了避免出现这种情况,我们必须给变量加上引号if timeofdat yes ,这样即使是空变量也提供了合法的测试条件,,if yes ...

2013-07-19 12:07 0 37351 推荐指数:

查看详情

shell脚本报错:"[: =: unary operator expected"

shell脚本报错:"[: =: unary operator expected" 在匹配字符串相等时,我用了类似这样的语句: if [ $STATUS == "OK" ]; then echo "OK" fi 在运行时出现了 [: =: unary ...

Thu Jan 24 00:56:00 CST 2019 0 561
shell脚本执行报错[: 0: unary operator expected

在执行shell脚本,if判断语句报错 #!/bin/bash if [ 0 == $testNum ] then echo "Check Result:0" fi    testNum使用时没有定义,无赋值是空(原本是有定义的,只是笔误写错类似tsetNum了),执行 ...

Tue Jul 10 04:34:00 CST 2018 0 7246
[: -ge: unary operator expected 错误

运行报错 : line 5: [: -ge: unary operator expected 错误原因: 由于变量rate初始化赋值为空,那么就成了 [ -ge "10"] 了,显然 [ 和 "10" 不相比较并且缺少了 [ 符号,所以报了这样的错误。 解决办法 ...

Sun Oct 11 02:25:00 CST 2015 0 2092
shell脚本报错退出

shell脚本中,比如有以下的代码: cd /root/test88 rm -rf backup 如果目录/root/test88不存在,脚本不会停止,依然会执行rm -rf backup这个命令 要让脚本停止执行: #!/bin/bash -e 或 set -e ...

Mon Nov 20 20:37:00 CST 2017 0 2142
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM