dash vs. bash
dash
通常使用sh
作为shell
脚本的执行命令,其位于
$ which sh
/bin/sh
其是一个链接,指向
$ file /bin/sh
/bin/sh: symbolic link to dash
所以dash
是默认解释器
$ file /bin/dash
/bin/dash: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 2.6.32, BuildID[sha1]=504637666875a5d526ef51acfe601c99efc99114, stripped
bash
在编写shell
文件时,会在开头加上如下语句
#!/bin/bash
其含义是在没有指定解释器时,使用/bin/bash
作为脚本解释器执行
$ file /bin/bash
/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 2.6.32, BuildID[sha1]=6f072e70e3e49380ff4d43cdde8178c24cf73daa, stripped
sh vs. dash vs. bash
sh
是一种编程语言,指的是shell
命令语言,其规范由POSIX standard指定bash(the GNU Bourne-Again Shell)
和dash(the Debian Almquist Shell)
是兼容sh
规范的脚本解释器- 对于
Debian
和Ubuntu
系统而言,其默认的sh
链接指向的是dash
bash
能实现的功能比dash
多,具体差别参考bash和dash区别,所以执行脚本时使用bash
$ bash test.sh