#!/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.
阅读(2343) | 评论(0) | 转发(0) |