我有兩個幾乎完全相同的bash腳本。一個人工作,一個人不工作,我不知道發生了什麼。下面是腳本:bash腳本中的Standard_in錯誤
這一個正常工作:
#!/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 ""
這兩個文件是相同的,除了目錄(土方VS立式)和節目名稱(earthmove vs vertical)。我知道這是因爲我通過複製和粘貼第一個來創建第二個。運行第二個腳本的結果是:
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.
有很多更多的線路,其中「...」是的,但他們基本上只是在同樣的想法的變化。
什麼是」垂直「?什麼是'earthmove'? – wilhelmtell 2010-06-29 18:24:16
你能用'flatroad'文件自己運行'$ CURDIR/Release/vertical'嗎?這是否會產生所有相同的錯誤? – 2010-06-29 19:14:05
vertical和earthmove是兩個C++程序。是的,從命令行運行「vertical -f flatroad.csv」可以正常工作。 – Jessica 2010-06-29 19:43:31