2010-06-29 69 views
9

我有兩個幾乎完全相同的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. 

有很多更多的線路,其中「...」是的,但他們基本上只是在同樣的想法的變化。

+0

什麼是」垂直「?什麼是'earthmove'? – wilhelmtell 2010-06-29 18:24:16

+0

你能用'flatroad'文件自己運行'$ CURDIR/Release/vertical'嗎?這是否會產生所有相同的錯誤? – 2010-06-29 19:14:05

+0

vertical和earthmove是兩個C++程序。是的,從命令行運行「vertical -f flatroad.csv」可以正常工作。 – Jessica 2010-06-29 19:43:31

回答

0

檢查垂直目錄的內容。其中一個CSV文件的名稱中是否有空格或奇數字符?嘗試圍繞保持在報價文件名變量:

"\"${filename}\"" 
+0

當前在Vertical/utest中的唯一文件是flatroad.csv和flatroad.res。 我嘗試了您的建議,除了所有其他錯誤,我現在還得到以下內容: 「Test flatroad.csv」cat:/ home/jessica/Documents/Development/road/Vertical/utest/flatroad。 csv「.res:沒有這樣的文件或目錄」 – Jessica 2010-06-30 17:01:16

+0

/home/jessica/Documents/Development/road/Vertical/utest中有哪些文件? 也可以嘗試在bash開啓詳細模式: $設置-v 你可以將其關閉「設置+ V」 – pborenstein 2010-06-30 20:35:39

9

的錯誤消息是由bc生產。問題是在文件「$ HOME/Documents/Development/road/Vertical/utest/$ file.res」中沒有包含「S:S:N:I :: O:P ...」之類的東西在另一個腳本中使用的相應文件。很有可能你期望這個文件包含一個單一的數值,而不是現在的文件。

+0

flatroad.res(此時在目錄中唯一的res文件)只包含「 0.0「(減去引號),這是一個單一的數值。 – Jessica 2010-06-30 16:55:38

+1

@Jessica:然後'$ value'的值包含'bc'不理解的東西。 – 2010-07-01 00:09:28

0

(standard_in)1:語法錯誤

該錯誤將通過使用的perl代替bc命令來解決,

$(perl的-e「打印$ B + $ C 「)