Chinaunix首页 | 论坛 | 博客
  • 博客访问: 371955
  • 博文数量: 55
  • 博客积分: 1033
  • 博客等级: 少尉
  • 技术积分: 603
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-21 13:36
文章存档

2013年(4)

2012年(51)

分类: LINUX

2012-08-29 08:50:38

学习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 查到。。

你还可以查阅:
阅读(1371) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~