shell 报错:unary operator expected"
2014-08-29 11:47
447 查看
一直学习perl,shell都忘得差不多了,今天写了个小脚本,判断脚本第二个变量不等于某字符串时的操作。
if [ $? -eq 0 ] && [ $2 != "wp" ]
then
: #略
fi
如果不加第二个变量,运行时会出现[: !=: unary operator expected"的报错,最后调试时发现
[ != "wp"]
原来shell的变量不定义时会出现这种情况,那就直接双括号吧。
[[ != "wp"]]
if [ $? -eq 0 ] && [ $2 != "wp" ]
then
: #略
fi
如果不加第二个变量,运行时会出现[: !=: unary operator expected"的报错,最后调试时发现
[ != "wp"]
原来shell的变量不定义时会出现这种情况,那就直接双括号吧。
[[ != "wp"]]
相关文章推荐
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- linux编程--shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错"[: =: unary operator expected"的解决方案
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- 【shell】 shell脚本报错:"[: =: unary operator expected"
- shell 脚本报错"[: =: unary operator expected"