ubuntu10.04 shell编程 if-else条件判定出现unexpected operator错误
来源:互联网 发布:centos中文 编辑:程序博客网 时间:2024/05/18 09:11
http://nubnub.blog.163.com/blog/static/169186347201191591835616/
read -p "Please input (Y/N): " yn
if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
echo "OK,continue"
exit 0
elif [ "$yn" == "N" ] || [ "$yn" == "n" ]; then
echo "Oh,interrupt"
exit 0
else
echo "I don't know what your choice is"
exit 0
fi
输入Y或N出现如下信息
[: 19: Y: unexpected operator
[: 19: Y: unexpected operator
[: 19: Y: unexpected operator
[: 19: Y: unexpected operator
因为ubuntu默认的sh是连接到dash的,又因为dash跟bash的不兼容所以出错了,执行时可以把sh换成bash 文件名.sh来执行,成功。
修改sh默认连接到bash的一种方法:
sudo dpkg-reconfigure dash
选择no即可.第二种:
在某个论坛看到别人讨论的结果。
将== 改为=就行了,dash判断字符串相等用 的是=。
- ubuntu10.04 shell编程 if-else条件判定出现unexpected operator错误
- Linux shell “if else” 与 条件判定
- Shell编程中if-elif-else条件分支语句测试
- Linux if表达式出现unexpected operator
- linux shell 条件判断if else, if elif else....
- ubuntu9.04 shell编程 [: 10: y: unexpected operator
- UBUNTU14.04 SHELL编程 [: 10: Y: UNEXPECTED OPERATOR
- Linux shell script遇到unexpected operator错误
- shell 中的条件判断(if else)
- shell if else 用法 syntax error near unexpected token `then'
- unexpected operator--shell script
- shell脚本unexpected operator
- 错误:unexpected operator
- Linux--Shell脚本(二)条件判断之if else
- 条件if-else
- shell if else
- shell if else
- Shell if else语句
- Linux简单Socket编程示例
- shell入门(一)
- 动态链接库(.so)
- C#窗体间传递控件参数
- AS3 Starling extends Particle System 分析
- ubuntu10.04 shell编程 if-else条件判定出现unexpected operator错误
- Java中的synchronized、Object.wait()、Object.notify()/notifyAll()的使用
- CAN总线技术在船舶监控系统的应用
- error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
- 库和框架区别
- {windows修改}之个人重装系统必做的一件事
- C++图像处理 -- 图像黑白调整应用
- linux主机安装pdo的教程
- SPRING.NET 1.3.2 学习16--使用depends-on