我有两个几乎相同的bash脚本。一个工作,一个不工作,我无法弄清楚发生了什么。以下是脚本:
这个很好用:
#!/bin/bash
CURDIR=$HOME/Documents/Development/road/Earthmoving
TOL=0.05
echo -e "\nRunning Unit Tests"
echo -e "------------------\n"
for infile in $CURDIR/utest/*.csv
do
file=$(basename $infile .csv)
echo -n " Test $file"
value=`$CURDIR/Release/earthmove -f $infile`
res=`cat $CURDIR/utest/$file.res`
if [ "$(echo "$res+$TOL*$res >= $value && $res-$TOL*$res <= $value" | bc)" -eq 1 ]; then
echo -e "\t\t PASSED."
else
echo -e "\t\t FAILED."
fi;
done
echo ""
但是这个给了我各种错误:
#!/bin/bash
CURDIR=$HOME/Documents/Development/road/Vertical
TOL=0.05
echo -e "\nRunning Unit Tests"
echo -e "------------------\n"
for infile in $CURDIR/utest/*.csv
do
file=$(basename $infile .csv)
echo -n " Test $file"
value=`$CURDIR/Release/vertical -f $infile`
res=`cat $CURDIR/utest/$file.res`
if [ "$(echo "$res+$TOL*$res >= $value && $res-$TOL*$res <= $value" | bc)" -eq 1 ]; then
echo -e "\t\t PASSED."
else
echo -e "\t\t FAILED."
fi;
done
echo ""
除了目录(Earthmoving vs Vertical)和程序名称(earthmove vs vertical)之外,这两个文件是IDENTICAL。我知道这是因为我通过复制和粘贴第一个来创建第二个。运行第二个脚本会产生以下结果:
Running Unit Tests
------------------
Test flatroad(standard_in) 1: illegal character: S
(standard_in) 1: syntax error
(standard_in) 1: illegal character: :
(standard_in) 2: illegal character: S
(standard_in) 2: illegal character: :
(standard_in) 2: syntax error
(standard_in) 2: illegal character: N
(standard_in) 2: illegal character: :
(standard_in) 2: illegal character: I
(standard_in) 2: illegal character: :
(standard_in) 2: illegal character: :
(standard_in) 2: illegal character: O
(standard_in) 2: illegal character: :
(standard_in) 3: illegal character: P
(standard_in) 3: illegal character: :
(standard_in) 3: syntax error
(standard_in) 3: illegal character: M
(standard_in) 3: illegal character: :
(standard_in) 3: illegal character: H
(standard_in) 3: illegal character: :
(standard_in) 3: illegal character: :
(standard_in) 4: illegal character: P
(standard_in) 4: illegal character: :
(standard_in) 4: syntax error
(standard_in) 4: illegal character: M
(standard_in) 4: illegal character: :
(standard_in) 4: illegal character: H
(standard_in) 4: illegal character: :
(standard_in) 4: illegal character: :
(standard_in) 5: syntax error
(standard_in) 5: illegal character: :
(standard_in) 6: illegal character: P
(standard_in) 6: illegal character: :
(standard_in) 6: illegal character: M
(standard_in) 6: syntax error
(standard_in) 6: illegal character: :
(standard_in) 7: syntax error
(standard_in) 7: illegal character: :
(standard_in) 8: illegal character: P
(standard_in) 8: illegal character: :
(standard_in) 8: syntax error
(standard_in) 8: illegal character: M
(standard_in) 8: illegal character: :
(standard_in) 15: syntax error
(standard_in) 16: syntax error
(standard_in) 16: illegal character: M
(standard_in) 16: illegal character: I
(standard_in) 16: illegal character: P
(standard_in) 17: syntax error
(standard_in) 18: illegal character: T
(standard_in) 18: illegal character: S
(standard_in) 18: illegal character: T
(standard_in) 18: syntax error
(standard_in) 19: illegal character: T
(standard_in) 19: illegal character: S
(standard_in) 19: illegal character: T
(standard_in) 19: syntax error
(standard_in) 20: illegal character: T
(standard_in) 20: illegal character: S
(standard_in) 20: illegal character: T
(standard_in) 20: syntax error
(standard_in) 21: illegal character: T
.
.
.
(standard_in) 90: illegal character: I
(standard_in) 90: illegal character: O
(standard_in) 90: syntax error
(standard_in) 90: illegal character: P
(standard_in) 90: illegal character: I
(standard_in) 90: illegal character: I
(standard_in) 90: illegal character: T
(standard_in) 91: syntax error
(standard_in) 91: syntax error
(standard_in) 91: syntax error
(standard_in) 91: syntax error
(standard_in) 93: illegal character: S
(standard_in) 93: syntax error
(standard_in) 94: illegal character: O
(standard_in) 94: syntax error
(standard_in) 95: syntax error
(standard_in) 96: illegal character: U
(standard_in) 96: syntax error
(standard_in) 96: illegal character: '
(standard_in) 96: illegal character: O
(standard_in) 96: illegal character: '
FAILED.
“......”还有很多行,但它们基本上只是同一个想法的变体。
答案 0 :(得分:10)
错误消息由bc
生成。问题是在“$ HOME / Documents / Development / road / Vertical / utest / $ file.res”文件中有“S:S:N:I :: O:P ...”之类的内容在另一个脚本中使用的相应文件。您可能希望该文件包含单个数值而不是现在的任何数值。
答案 1 :(得分:0)
检查Vertical目录的内容。您的某个CSV文件名称中是否包含空格或奇数字符?尝试使用引号括起文件名的变量:
"\"${filename}\""
答案 2 :(得分:0)
(standard_in)1:语法错误
使用 perl 代替bc命令
可以解决此错误$(perl -e“print $ b + $ c”)