2012-03-06 44 views
0

我遇到了解析和比較數據的問題,如下所示。使用linux進行分析數據的比較以及在'if'或while循環中使用該比較

thinningCriteria="$(cat thinningCriteria$j.k)" 
minThickElement="$(cat minimumThickness$j.k)"; 
d= "$(cat BHF$j.k)"; 
echo $d 
echo $minThickElement 
echo $thinningCriteria 

對於它給出的錯誤如下,所以這是第一個問題。

N o r m a l t e r m i n a t i o n 
./dynaOffenRigid.sh: line 137: 1000: command not found 

其中

d= "$(cat BHF$j.k)"; is on line 137 and the file has a value of 1000 

其次我必須比較像下面

if (($minThickElement -lt $thinningCriteria)) 

then 

fi 
在這種情況下

誤差如下兩個值。

999979 
986667 
./dynaOffenRigid.sh: line 147: ((: -lt 986667 : syntax error in expression (error token is "986667 ") 

the only value in BHF$j.k is 1000 
the only value in thinningCriteria$j.k is 999979 
the only value in minimumThickness$j.k is 986667 

我不知道我在比較什麼時候做錯了,爲什麼我的shell有錯誤。 請所有告訴我,而我循環使用

while [ $minThickElement -gt $thinningCriteria ] but same error. 

的我希望從專家的一些建議使用。因爲我無法找到解決方案。

問候

回答

0

問題1: 變化

d= "$(cat BHF$j.k)"; 

d="$(cat BHF$j.k)" 

問題2:

嘗試

[[ $minThickElement -lt $thinningCriteria ]] 
+0

因爲它再次說找不到命令。我用d =「$(貓BHF $ j.k)」 echo $ d – 2012-03-06 11:19:59

+0

@hamaskhan,你複製我的線? '='後有空白。去掉它。 – Kent 2012-03-06 11:21:48

+0

問題是我正在使用一個循環,其中j是計數器,所以它必須從BHF1中獲取第一個循環的值,而將BHF2中的值用於循環2.但是,我認爲它會混淆兩個$,我應該如何解析它? – 2012-03-06 11:29:23