FAQ: bash
🆀 .bashrc
などのシェル設定ファイルの読み込み順について教えてください
🅐 読み込み順についての正式な情報源は、bash(1)
マニュアルです。(man bash
コマンドで表示できます。)
以下 4 つの場合でシェル設定ファイルの読み込み順が異なります。bash(1)
マニュアルの該当の記載を併記します。
1, interactive, login shell
ssh
でログインした場合やsu -
を実行した場合など。(su -
はsu --login
と同じ。ログインシェルとしてシェルを起動せよの意味。)
qlogin
した場合もこれに該当します。
~/.bash_profile
, ~/.bash_login
, ~/.profile
の順で探して最初に存在したファイルを読み込みます。
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file
/etc/profile
, if that file exists. After reading that file, it looks for~/.bash_profile
,~/.bash_login
, and~/.profile
, in that order, and reads and executes commands from the first one that exists and is readable. The--noprofile
option may be used when the shell is started to inhibit this behavior.
したがって bash の動作としては SSH でログインした際には~/.bashrc
は自動的には読み込まれませんが、
上記のシェル設定ファイルの中に~/.bashrc
を読み込むように書かれている場合が多い、という関係にあります。