學習shell 時遇到的一些問題(unexpected operator) 和解決方法
read -p "please input your choice(Y/N):" choice
[ "$choice" == "Y" -o "$choice" == 'y' ] && echo "OK,continue" && exit 0
[ "$choice" == 'N' -o "$choice" == 'n' ] && echo "oh ,interrupt!" && exit 0
echo " i donnot know what your choice is " && exit 0
編譯後總是有錯誤:
sh7.sh: 11: [: Y: unexpected operator
sh7.sh: 11: [: Y: unexpected operator
sh7.sh: 15: [: Y: unexpected operator
sh7.sh: 15: [: Y: unexpected operator
解決方法就是:
(1) : sudo dpkg-reconfigure dash 選NO
將ubuntu 默認的shell 連接的dash 改爲傳統的 bash
lrwxrwxrwx 1 root root 4 8月 11 09:53 /bin/sh -> dash (爲修改以前)
lrwxrwxrwx 1 root root 4 8月 11 09:53 /bin/sh -> bash
因爲dash 和bash 不兼容才致使了此類問題的發生。。
(2):將==改爲= :由於在dash 中默認的 判斷語句是=。。
對於具體的dash 和bash 均可以使用man 查到。。
你還能夠查閱:
http://www.51testing.com/html/38/225738-208702.html