[: ==: unary operator expected 解决方法

之前在写脚本时遇到了这样的错误

“[: ==: unary operator expected”

这是由于做判断的变量值为空导致的。

谷歌出解决方案:

在变量之后加任意字符。例如,要判断变量un是否为auto又要防止un为空出错则这样写

if [ ${un}x == autox]

当un为auto时,表达式为autox == autox,成立;

un为空,表达式为x == autox ,则不成立。

时间: 2024-07-30 21:10:36

[: ==: unary operator expected 解决方法的相关文章

shell脚本中 unary operator expected解决办法

if [ $USER = "oracle" ]; then     if [ $SHELL = "/bin/ksh" ]; then         ulimit -p 16384         ulimit -n 65536     else         ulimit -u 16384 -n 65536     fi fi 解决方案如下: if [ "$USER" = "oracle" ]; then    if [

[: -ge: unary operator expected 错误

1 #!/bin/bash 2 3 rate=$(df -h |grep /dev/sda3 | awk '{print $5}' | cut -d "%" -f1) 4 5 if [ $rate -ge 10 ] 6 then 7 echo "Warning! /dev/sda3 is full!!" 8 fi 运行报错 : line 5: [: -ge: unary operator expected 错误原因: 由于变量rate初始化赋值为空,那么就成了 [

unary operator expected

问题:写的脚本执行的时候出现报错,如下 分析: (1)出现的脚本所在行为if [ $result -eq 0 ];then (2)报错unary operator expected的中文意思是应该使用一元运算符,也就是说这个$result假如 为空的话就成了 if [ -eq 0] ,系统就会认为是少了一个参数,只有一个 -eq 0,没有左边的参数, 所以就会出现上述报错 解决:可以将脚本改为if [[ $result -eq 0 ]];then,多加一对[]号.至于为什么,我也是百度的

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

shell脚本报错:"[: =: unary operator expected" md5_109a="81ab961153b62d207f0f517048881b5d" md5_109b=`md5sum install.bin|awk '{print $1}'` if [ $md5_109a != $md5_109b ] 原因,当文件install.bin不存在时, $md5_109b为空这样对比字符串就变成了 if [ 81ab961153b62d207f0f5

shell 报错:unary operator expected"

一直学习perl,shell都忘得差不多了,今天写了个小脚本,判断脚本第二个变量不等于某字符串时的操作. if [ $? -eq 0 ] && [ $2 != "wp" ] then : #略 fi 如果不加第二个变量,运行时会出现[: !=: unary operator expected"的报错,最后调试时发现 [ != "wp"] 原来shell的变量不定义时会出现这种情况,那就直接双括号吧. [[ != "wp"

bullet, iOS真机编译错误error: identifier or immediate expression expected解决方法

刚才发现c3dEngine2(http://git.oschina.net/wantnon2/c3dEngine2 或 https://github.com/wantnon2/c3dEngine2)的bulletTest1 demo在iOS真机上编译不过,报error: identifier or immediate expression expected的编译错误. google了一下,找到下面帖子:http://www.bulletphysics.org/Bullet/phpBB3/view

shell脚本执行报错[: 0: unary operator expected

在执行shell脚本,if判断语句报错 #!/bin/bash if [ 0 == $testNum ] then echo "Check Result:0" fi testNum使用时没有定义,无赋值是空(原本是有定义的,只是笔误写错类似tsetNum了),执行转换后实际为 if [ 0 == ] 不相等,且少[符号错误:规避如下 #!/bin/bash if [[ 0 == $testNum ]] then echo "Check Result:0" fi 使用

Bean named '...' is expected to be of type [...] but was actually of type [com.sun.proxy.$Proxy7解决方法

报错 三月 07, 2017 8:09:52 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh信息: Refreshing org[email protected]41cf53f9: startup date [Tue Mar 07 20:09:52 CST 2017]; root of context hierarchy三月 07, 2017 8:09:52 下午 org.s

编绎报错,解决方法objc_msgSend too many arguments to function call,expected 0, have3 (转)

  编绎报错,objc_msgSend too many arguments to function call,expected 0, have3 解决方法: