我採購軟件的shell腳本,但我不斷收到以下錯誤語句(?):猛砸正確的,如果未正確執行
>source thefile.sh
'else' builtin not inside of if block
我檢查了理論上的錯誤塊,我不能發現什麼不對的結構
if [ condition ]
then
if [ condition2 ]
then
dostuff
else
dostuffagain
fi
else # this is the else which generates the error
stuffstuffstuff
fi
我看不出什麼錯:這是一個嵌套的if/then和每一個如果由它自己的網絡連接終止。爲什麼外殼會對此感到不安?
是否'thefile.sh'直接執行時沒有錯誤執行?這可能是一個有價值的信息,因爲例如當採購 – Aaron
替換'condition'和'stuff'有意義時,shebangs會被忽略,您的示例適用於我。 – Robin479
檢查http://shellcheck.net上的整個文件。祝你好運。 – shellter