最終更新日

システム設定ファイルを知ろう〜~/.bash_profile〜

 .bash_profileは,bashシェル実行時に自動的に読まれるスクリプトが記述されている環境設定ファイルである。各ユーザーのホームディレクトリ直下にある。

 このファイルが存在しない場合には,~/.profileが読み込まれ,Red Hat Linux 7.2の標準設定では次のようなファイル内容になっている。

$ cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs
PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

 ここで,同じくbashの環境設定ファイル「.bashrc」の存在も気になるが,.bash_profileに次のような行を追加しておけば自動的に.bashrcの内容も読み込まれるようになる。

source .bashrc

 ちなみにbashでログイン時には次の順番で存在を確認し,環境設定として読み込まれる。

1. ~/.bash_profile
2. ~/.bash_login
3. /etc/profile