2013-08-02 50 views
0

試圖寫一個bash,如果定義了環境變量中指定要使用的命令。這樣做如下:Bash沒有這樣的文件或目錄

if [ -z $MY_DIFF ]; 
then 
    echo Using standard diff $(which diff), change MY_DIFF env variable to use a different one. 
    echo $(which diff) 
    $diffv=$(which diff) 
else 
    $diffv=$MY_DIFF 
fi 

$diffv c.xml c2.xml 

但我發現了:

./bash.sh: line 10: =/opt/gnu/bin/diff: No such file or directory 
./bash.sh: line 13: c.xml: command not found 

我敢肯定,該文件存在,我也有權執行。任何想法可能是什麼問題?

+0

您可以包括行號更清楚地顯示在錯誤指向? –

+2

您在diff路徑前有一個'='。 – blackSmith

+0

請勿在作業左側使用$(在腳本上運行時,這是從[ShellCheck](http://www.shellcheck.net)輸出的文字)。 –

回答

3

刪除diffv之前的額外$分配。用途:

diffv=$(which diff) 

和:

diffv=$MY_DIFF 

隨着$你:

<diffv value, empty>=<MY_DIFF value, or which diff> 
=/opt/gnu/bin/diff 
相關問題