-1
這是我的shell腳本的代碼:猛砸判斷得到意想不到的結果
#! /bin/bash
if ["$SHELL" = "/bin/bash"];then
echo "this is bash"
elif ["$SHELL" = "aa"];then
echo "this is aa"
else
echo "this is not /bin/bash, but $SHELL"
fi
爲什麼我執行test_bash_03腳本文件獲取else
結果?它不應該是:this is bash
aircraftdeMacBook-Pro:bash_demo ldl$ ./test_bash_03
./test_bash_03: line 3: [/bin/bash: No such file or directory
./test_bash_03: line 5: [/bin/bash: No such file or directory
this is not /bin/bash, but /bin/bash
我附和$SHELL
我也得到了/bin/bash
aircraftdeMacBook-Pro:bash_demo ldl$ echo $SHELL
/bin/bash
請注意這些錯誤?這是因爲他們。在你的'['和']'之前和之後添加空格。 – RealSkeptic
@RealSkeptic我明白了,謝謝。 – aircraft
你也可以使用http://www.shellcheck.net/來捕獲這樣的錯別字,並得到其他可能的問題 – Sundeep