当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 2 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 写shell关于bash 和 sh .的问题....14.04LTS
帖子发表于 : 2015-07-03 17:48 

注册: 2015-06-27 10:08
帖子: 26
系统: ubuntu14.04 LTS
送出感谢: 3
接收感谢: 0 次
今天写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 有什么区别???????


页首
 用户资料  
 
2 楼 
 文章标题 : Re: 写shell关于bash 和 sh .的问题....14.04LTS
帖子发表于 : 2015-07-03 18:13 

注册: 2009-08-04 16:33
帖子: 16886
送出感谢: 21
接收感谢: 1826
引用:
bash 和 sh 有什么区别???????

1. sudo ls -al /bin/bash
-rwxr-xr-x 1 root root 1021112 10月 8 2014 /bin/bash

2. sudo ls -al /bin/sh
lrwxrwxrwx 1 root root 4 2月 19 2014 /bin/sh -> dash
2-1. sudo ls -al /bin/dash
-rwxr-xr-x 1 root root 121272 2月 19 2014 /bin/dash

3. 意思是 當你使用 sh
實際執行的是 dash
3-1. 注意 並不是所有的 Linux 發行版本 都是這樣

4. http://askubuntu.com/questions/141928/w ... d-bin-bash
What is difference between #!/bin/sh and #!/bin/bash?

5. http://www.linuxquestions.org/questions ... ix-912790/
difference between /bin/bash and /bin/dash and compatibility with POSIX


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 2 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 0 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译