#!/bin/bash 与 #!/bin/sh 有什么区别? 即使 ls -l /bin/sh -> bash ??
时间:2011-06-13
来源:互联网
呵呵, 先声明, /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.
#!/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
sh->bash即你当前用的shell为bash
作者: pcuer 发布时间: 2011-06-13
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28