$ ./example.sh Starting script... ./example.sh: line 3: [: /path/to/nonexistent_file: binary operator expected File does not exist. Script finished. 解决方法: 确保文件路径正确或处理文件不存在的情况: 代码语言:txt 复制 #!/bin/bash
$ test 1 '>=' 2 -bash: test: >=: binary operator expected 可以看到,test 1 '>' 2命令返回 1,判断结果正确。 这其实是一个判断字符串的条件表达式。 而test 1 '>=' 2命令则执行报错,因为判断字符串的条件表达式不支持>=这个操作符。 同样也不支持<=操作符。 刚接触test命令的常见误区就是认为条件...
-bash: test: go: binary operator expected 在这个测试例子中,在test -n后面的字符串包含空格,又没有用双引号把字符串括起来,那么参数个数会变多。 这里提供了三个参数,-n也是一个参数。 参考上面 "3 arguments" 的说明,提供三个参数时,预期第二个参数是binary conditional operators。 由于这里没有提供,执行...
if test -z `cat filename` 当filename为空或者只有一行没有空格的字符串的时候,一切正常,反之,则会报:too many arguments,甚至是: binary operator expected之类的错误。 原因分析: filename中的空格回车等迷惑了bash。 如果环境变量没放在双引号中,那么bash 认为条件中的自变量过多。 可以用双引号将字符串自变...
expr可用于整数运算,也可以处理字符串,使用expr进行运算时,表达式和运算符之间必须加空格,乘号*和小括号()前要加\转义(小括号是左右括号前都要加\转义)。 (( expression ))会对算术表达式求值,如果表达式的值不是0,则返回状态是0,否则返回状态是1,这和let "expression"等价。
bash: [: buggy: binary operator expected nc10@your-5554c55be4 ~[ -f "$i" ] && echo yes yes nc10@your-5554c55be4 ~只要档案名有空格就出错, 不太大的脚本或是常重复用的代码,我本人不会写太多函数, 我写一个看看,,! /bin/sh using traditional sh, not bash, for portable ...
# test "obama" =~ "^o.*"-bash: test:=~: binary operator expected# test "obama" =~ ^o.*-bash: test:=~: binary operator expected# [ "obama" =~ "^o.*" ]-bash:[:=~: binary operator expected# [ "obama" =~ ^o.* ]-bash:[:=~: binary operator expected# [[ "obama" =~...
bash: [: =~: binary operator expected 2 [root@qfedu.com ~]# [[ "$USER" =~ ^r ]];echo $? 0 2、Shell 脚本执行测试 # 执行脚本: [root@qfedu.com ~]# ./01.sh [root@qfedu.com ~]# bash 01.sh # 需要执行权限 # 不需要执行权限 在子shell中执行 在子shell中执行 [root@qfedu....
linuxbash中toomanyarguments问题的解决⽅法 判断⼀个⽂件的内容是不是为空,使⽤语句:if test -z `cat filename`当filename为空或者只有⼀⾏没有空格的字符串的时候,⼀切正常,反之,则会报:too many arguments,甚⾄是: binary operator expected之类的错误。原因分析:filename中的空格回车等...
The eq operator is a binary operator and needs two arguments, therefore, Bash complains with “unary operator expected”. We’ll check the possible solutions to handle this error in the next sections. 3. Preventing the Error by Quoting the Variables We can double-quote our variables to ...