LoginSignup
5
4

More than 5 years have passed since last update.

Yet Another .bash_profile vs .bashrc + .profile 備忘録

Last updated at Posted at 2016-04-21

基本の基本

.bash_profile には、まず.profile.bashrc を読み込む設定を記述する。(ソース: bash - Difference between .bashrc and .bash_profile)

抜粋:

if [ -r ~/.profile ]; then . ~/.profile; fi
case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac

.profile には、環境変数の export をひたすら記述する。シェル自身と、シェルから実行されていくすべてのプロセスに影響を与えたいような設定(つまりはだいたいが環境変数の export)をここに記述する。bash をログインシェルとして介さないもろもろがあったりする場合にも、 .profile に書いておくと読み込まれる場合がある様子なので、できるかぎりこっちに寄せた方がいいっぽい。(ソース)

対話シェルの時だけあればいい設定はすべて .bashrc に書く。 alias もは、下の理由によりおそらくここに記載しないとおかしなことに。

alias を profile に書いたら?

alias は shell からコマンドを exec したら受け継がれない様子。ソース

対話的 bash の中でもう一回 bash を実行したら、 .bash_profile.profile のみに記述がある alias は、その新しく起動した bash では使えない。ので、 .bashrc に記述されるべき。

補足: ubuntu に ssh したときに出る welcome メッセージとか

profile 系のどこかに記述があるので、最初のログイン時に表示される仕組みらしい。

補足2: mac os x の端末の場合

タブを開くたびに毎回ログインシェルを立ち上げている。ので、 .bash_profile のみにすべて記述していても(だいたい)問題なく動く

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4