unary operator expected

问题:写的脚本执行的时候出现报错,如下

分析:

(1)出现的脚本所在行为if [ $result -eq 0 ];then

(2)报错unary operator expected的中文意思是应该使用一元运算符,也就是说这个$result假如

为空的话就成了 if [ -eq 0] ,系统就会认为是少了一个参数,只有一个 -eq 0,没有左边的参数,

所以就会出现上述报错

解决:可以将脚本改为if [[ $result -eq 0 ]];then,多加一对[]号。至于为什么,我也是百度的

时间: 2024-12-30 12:02:48

unary operator expected的相关文章

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

[: -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 解决方法

之前在写脚本时遇到了这样的错误 “[: ==: unary operator expected” 这是由于做判断的变量值为空导致的. 谷歌出解决方案: 在变量之后加任意字符.例如,要判断变量un是否为auto又要防止un为空出错则这样写 if [ ${un}x == autox] 当un为auto时,表达式为autox == autox,成立: un为空,表达式为x == autox ,则不成立.

shell 报错:unary operator expected"

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

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 [

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 使用

字符串判空有空格报错:binary operator expected

使用-z或-n对一个变量判空时,需要注意若直接使用[ -n ${ARG} ]这种形式,若${ARG}中有空格将会报错, #!/bin/bash ARG="sd dd" if [ -n ${ARG} ]; then echo 'ARG:' ${ARG} else echo 'ARG is empty.' fi 输出: line 27: [: sd: binary operator expected ARG is empty. 解决方法,使用[[ -n ${ARG} ]]或[ -n &qu

流媒体平台搭建

1       目标 希望建设一个流媒体平台(类似音乐平台),通过流媒体平台维护相关流媒体资源. 2       主要功能要求 主要功能可以包括:流媒体内容维护(信息维护.流媒体文件上传等).支持RTSP(Real-Time Streaming Protocol,实时流媒体协议)和RTP/RTCP(Real-Time TranCPort Protocol/RTP Control Protocol,实时传输协议/RTP控制协议)进行流媒体播放.DSS给出的性能参数为:默认1000用户同时在线,可以

Zimbra 8.7.1GA更新

公司的zimbra 8.5.0用了差不多一年,看zimbra发布了新版本,直接升级8.7.1失败,于是先升级到8.6.0,希望能后续能直接升级到8.7.1,后来发现是绕不开的坑,必须把问题解决了才可以.于是在备份好系统快照的前提下,参考网络上的资料,开始了以下的升级.follow me--. 1.系统环境:    cat /etc/system-release     CentOS Linux release 7.3.1611 (Core)     uname -a     Linux mail