[: 11: y: unexpected operator问题

Posted 冬日降临

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[: 11: y: unexpected operator问题相关的知识,希望对你有一定的参考价值。

《私房菜》上的shell脚本问题:

转载:[: 11: y: unexpected operator问题

脚本如下:%

 

#!/bin/bash
# Program:
#    This program shows the users choice
# History:
#2018/01/03
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin& 
export PATH

read -p "Please input (Y/N): " yn
[ "$yn" == "Y" -o "$yn" == "y" ] &&echo "OK, continue" && exit0
[ "$yn" == "N" -o "$yn" == "n" ] &&echo "Oh, interrupt!" && exit0
echo "I don‘t know what your choice is"&& exit 0

 

执行时总提示错误9

 

Please input (Y/N): y
[: 10: y: unexpected operator
[: 11: y: unexpected operator
I dont know what your choice is

 

因为ubuntu默认的sh是连接到dash的,又因为dash跟bash的不兼容所以出错了.执行时可以把sh换成bash文件名.sh来执行.成功.dash是什么东西,查了一下,应该也是一种shell,貌似用户对它的诟病颇多.
by the way修改sh默认连接到bash的一种方法:
sudo dpkg-reconfigure dash0 Q$ c+ `. U+ c2 K
选择no即可.

 

以上是关于[: 11: y: unexpected operator问题的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu 下执行脚本报错 [: 10: unexpected operator

解决Linux下编译.sh文件报错 unexpected operator Syntax error: word unexpected

Shell 判断语句出错 [: ==: unexpected operator

Babel 编译错误 SyntaxError: Unexpected token when using spread operator

Ionic2 Typescript 设备构建错误'uglifyjs failed: SyntaxError: Unexpected token operator «=», expected punc

编译OpenJDK8-u332:/bin/sh: 1: [: -a: unexpected operator/line 0: [: too many arguments