bash shell脚本遇到+0")syntax error: invalid arithmetic operator (error token is "的问题

2025-02-26 23:22:37
推荐回答(1个)
回答1:

LINE="Tests run: 196, Failures: 1, Errors: 1"
error=`echo $LINE|cut -d':' -f4`
ERROR=0
ERROR=$(($error+$ERROR))

你确定你是在用b.sh不是其他shell执行这个脚本?还有,你发的LINE=后面的引号是
全角的,是你输入错误还是原来脚本就用全角的? 把这下面这个复制粘贴到t.sh, 再报错,就是你系统的问题。我已经测试过两遍了。

#!/bin/bash
LINE="Tests run: 196, Failures: 1, Errors: 1"
error=`echo $LINE|cut -d':' -f4`
echo $error
ERROR=0
ERROR=$(($error+$ERROR))
echo $ERROR

测试结果:
chmod +x t.sh
./t.sh
1
1