2013/05/01

Linuxの/bin/sh

概要

Linuxの/bin/shはBourneシェルかと思いきや、実はBashへのシンボリックリンクになっています。Bashはshの上位互換のシェルなので基本的には問題ないらしいです。ちなみにshとして起動した場合は、sh互換モードというモードで起動するようです。

 $ ls -l `which sh`

 lrwxrwxrwx. 1 root root 4 10月  8 12:04 2012 /bin/sh -> bash

sh互換モード

bashのsh互換モードについての説明です。

シェルオプションの違い

bashで起動した場合とshで起動した場合のシェルオプションを比較してみます。

$ sh
$ set -o
allexport       off
braceexpand     on
emacs           on
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
history         on
ignoreeof       off
interactive-comments    on
keyword         off
monitor         on
noclobber       off
noexec          off
noglob          off
nolog           off
notify          off
nounset         off
onecmd          off
physical        off
pipefail        off
posix           on
privileged      off
verbose         off
vi              off
xtrace          off

$ bash
$ set -o
allexport       off
braceexpand     on
emacs           on
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
history         on
ignoreeof       off
interactive-comments    on
keyword         off
monitor         on
noclobber       off
noexec          off
noglob          off
nolog           off
notify          off
nounset         off
onecmd          off
physical        off
pipefail        off
posix           off
privileged      off
verbose         off
vi              off
xtrace          off

上記の結果を見ると分かると思いますが、shで起動した場合シェルオプションの25行目の「posix」が有効になっているのが分かります。このオプションの有効/無効の違いによってbashがBourneシェルに近い動作をするように切り替えています。

0 件のコメント:

コメントを投稿