#!/bin/bash 与 #!/bin/sh 有什么区别? 即使 ls -l /bin/sh -> bash ??

呵呵, 先声明, /bin/bash和/bin/sh区别, 在shell论坛里已经搜过以前的帖子, 但是没发现我想要的, 故而问之.... 大牛们不吝赐教啊~~

#!/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.

作者: binary_XY.Z   发布时间: 2011-06-13

回复 binary_XY.Z


    sh->bash即你当前用的shell为bash

作者: pcuer   发布时间: 2011-06-13