学习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 查到。。
你还可以查阅:
阅读(1380) | 评论(0) | 转发(0) |