Linuxの標準シェルとして採用されているbash(Bourne Again Shell)ですが設定ファイルとして以下の2つがあります。
この2つの違い(使い方)について、以下に記述します。
| .bashrc | bashを起動するたびに実行されます |
| .bash_profile | ログイン時に一度実行されます |
CentOSでは以下のように.bashrc, .bash_profileが記述されています。
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
# .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
以下のように編集してテストしてみます。
読み込まれた時、Read .bashrcと表示します。
# .bashrc
echo "Read .bashrc"
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
読み込まれた時、Read .bash_profileと表示します。
また環境変数TESTを設定してあります。
# .bash_profile
echo "Read .bash_profile"
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export TEST=sakura
export PATH
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi