今天写shell时与遇到的问题
代码如下:
#!/bin/bash
#program:
# this program show you choice
#history:
#2015.7.3 acceler first release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin:~/bin
export PATH
read -p "please input (y/n): " yn
if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
echo "OK,continue!"
exit 0
fi
if [ "$yn" == "N" ] || [ "$yn" == "n" ]; then
echo "Oh,interrupt"
exit 0
fi
echo "i don't konw what your choice is " && exit 0
保存为 1.sh
运行时输入:bash 1.sh 运行无误
运行时输入:sh 1.sh 出错错误如下:
1.sh: 10: [: y: unexpected operator
1.sh: 10: [: y: unexpected operator
1.sh: 14: [: y: unexpected operator
1.sh: 14: [: y: unexpected operator
i don't konw what your choice is
为什么会这样?....
bash 和 sh 有什么区别???????
bash 和 sh 的问题 求解
-
- 帖子: 26
- 注册时间: 2015-06-27 10:08
- 系统: ubuntu14.04 LTS
- vickycq
- 帖子: 4507
- 注册时间: 2011-03-20 13:12
- 系统: Debian
- 来自: 山东省寿光县
- 联系:
Re: bash 和 sh 的问题 求解
在现代Linux发行版中,/bin/sh是指向系统默认shell的软链接。在ubuntu和debian中,指向/bin/dash:
bash和dash有细微区别。参考:
http://stackoverflow.com/questions/5725 ... h-and-bash
http://askubuntu.com/questions/141928/w ... d-bin-bash
http://www.linuxfly.org/post/686/
http://www.linuxidc.com/Linux/2012-03/57493.htm
https://wiki.ubuntu.com/DashAsBinSh
请大神补充
代码: 全选
user@localhost ~ $ ll /bin/sh
lrwxrwxrwx 1 root root 4 Nov 8 2014 /bin/sh -> dash
http://stackoverflow.com/questions/5725 ... h-and-bash
http://askubuntu.com/questions/141928/w ... d-bin-bash
http://www.linuxfly.org/post/686/
http://www.linuxidc.com/Linux/2012-03/57493.htm
https://wiki.ubuntu.com/DashAsBinSh
请大神补充
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
欢迎所有 Debian GNU/Linux 用户