学习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