多くの場合/bin/sh
はbashであることが多いようで、例えば手元のMacで見てみると、
$ /bin/sh --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12) Copyright (C) 2007 Free Software Foundation, Inc.
となっている。 一方、DebianやUbuntuではdashというシェルが採用されているようだ。
man bash
してみると、
If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well.
と書いてあり、shとしてbashが起動されるとなるべくそれっぽく振る舞いますよと書かれてある。
ただこれが結構曲者で、実際には普通にfunction
句などを使えてしまうのでbashに依存したシェルスクリプトを書けてしまう。
bash依存のシェルスクリプトを書いてしまっていないかどうかはcheckbashisms
というコマンドで確認することができる。
ポータビリティを重視するなら気を付けましょう、という学びが得られた。