linux shell 学习时遇到的一些问题([: 11: y: unexpected operator)

linux shell 学习时遇到的一些问题([: 11: y: unexpected operator)

刚刚开始接触shell 很多不懂 遇到了一些问题(linux shell 学习时遇到的一些问题([: 11: y: unexpected operator))

#!/bin/sh
#Author : iwi_ac
read -p "Please input (Y/n)" ans

if [ "$ans" == "N" ]||[ "$ans" == "n" ]; then
 echo "No,I whill go back."
elif [ "$ans" == "Y" ]||[ "$ans" == "y" ]; then
 echo "Yes!"
else
 echo "Good!" 
fi

一直在出这个错误:

[: 11: y: unexpected operator
[: 11: y: unexpected operator
[: 11: y: unexpected operator
[: 11: y: unexpected operator


 改了一个小时 整个人都不好了。。

原因: Ubuntu 默认编译环境是 dash 得换用原始的bash编译 而我编译时候用的命令是 sh If.sh

最后用bash If.sh 就好了

再或者把 == 换成 = 因为dash判断的相等用 = 


root@jsjx-desktop:~/Sct# bash If.sh
Please input (Y/n)y
Yes!
root@jsjx-desktop:~/Sc# bash If.sh 
Please input (Y/n)n
No,I whill go back.
root@jsjx-desktop:~/Sc# bash If.sh
Please input (Y/n)w
Good!

根本上解决办法(网上借鉴):

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 不兼容才导致了此类问题的发生。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值