Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1450752
  • 博文数量: 263
  • 博客积分: 10851
  • 博客等级: 上将
  • 技术积分: 2627
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-26 22:40
文章分类

全部博文(263)

文章存档

2013年(4)

2012年(25)

2011年(33)

2010年(50)

2009年(138)

2008年(13)

分类: LINUX

2011-06-15 10:30:13

#!/bin/bash 与 #!/bin/sh 有什么区别? 即使 ls -l /bin/sh -> bash ??
使用#/bin/sh时, exec 改变FD指向到一个不存在的文件描述符, 整个shell就会直接退出..
> cat pp.sh
#!/bin/sh
ls abc
#exec 2>&6 6>&-
exec 2>&6
echo "hello"
> ./pp.sh
ls: cannot access abc: No such file or directory
./pp.sh: line 4: 6: Bad file descriptor

> cat pp.sh
#!/bin/bash
ls abc
#exec 2>&6 6>&-
exec 2>&6
echo "hello"
> ./pp.sh
ls: cannot access abc: No such file or directory
./pp.sh: line 4: 6: Bad file descriptor
hello
我看我机器上的/bin/sh 是 指向 /bin/bash的啊!
> ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Sep 26  2008 /bin/sh -> bash
> ls -l /bin/bash
-rwxr-xr-x 1 root root 755624 Feb 29  2008 /bin/bash
> sh --version
GNU bash, version 3.2.33(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
> bash --version
GNU bash, version 3.2.33(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
阅读(2290) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~