Skip to content

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规范的脚本解释器
  • 对于DebianUbuntu系统而言,其默认的sh链接指向的是dash

bash能实现的功能比dash多,具体差别参考bash和dash区别,所以执行脚本时使用bash

$ bash test.sh

相关阅读