bashの設定ファイルが読み込まれる順番
bashが起動する際、設定ファイルがどのような順番で読み込まれるかを調べてみた
maybe_execute_file (SYS_PROFILE, 1);
if (act_like_sh) /* sh */
maybe_execute_file ("~/.profile", 1);
else if ( (maybe_execute_file ("~/.bash_profile", 1) == 0) &&
(maybe_execute_file ("~/.bash_login", 1) == 0)) /* bash */
maybe_execute_file ("~/.profile", 1);
と書かれている
つまり、
/etc/profile を読み込む
↓
~/.bash_profile と ~/.bash_login を読み込む (もし、どちらのファイルも無ければ)
↓
~/.profile を読み込む
という流れで設定ファイルが読み込まれる。
一般的に個人のbashの設定は ~/.bashrc に書くことが多いが、bash自体は ~/.bashrc を読み込むように作られていない。 多くのLinuxディストリビューションでは ~/.bash_profile 等に ~/.bashrc を読み込む設定が書かれている。
Debianでは
Squeezeの場合
/etc/profile 内に /etc/bash.bashrc を読み込む設定がある
~/.profile 内に ~/.bashrc を読み込む設定がある
~/.bash_profile や ~/.bash_login を作成すると、~/.profile が読み込まれなくなるので注意が必要
etchの場合
/etc/profile 内に /etc/bash.bashrc を読み込む設定がある
~/.bash_profile 内に ~/bashrc を読み込む設定がある
Mac OS X では
Lionの場合
/etc/profile 内に /etc/bashrc を読み込む設定がある
~/.profile があるが、他のファイルを読み込む設定は記述されていない
~/.bash_profile や ~/.bash_login を作成すると、 ~/.profile が読み込まれなくなるので注意が必要