LoginSignup
3
3

More than 1 year has passed since last update.

Linuxの環境変数の設定ファイルの読み込まれる順番

Posted at

Linuxの環境変数の設定ファイルの読み込まれる順番について、毎回調べているような気がするので、メモとして残します。

1. ログイン時に読み込まれる設定ファイル

読込順 ファイル1 ファイル2 ファイル3 概要
1 /etc/profile /etc/profile.d 「/etc/profile」の中で「/etc/profile.d」配下のシェルと「/etc/bashrc」が呼び出される。
/etc/bashrc
2 ~/.bash_profile ~/.bashrc /etc/bashrc 「~/.bash_profile」の中で「~/.bashrc」が呼び出され、「~/.bashrc」の中で「/etc/bashrc」が呼び出される。
3 ~/.bash_login 「~/.bash_profile」が存在しない場合呼び出される。
※CentOS8ではデフォルトでは存在しないファイル。
4 ~/.profile 「~/.bash_profile」と「~/.bash_login」が存在しない場合呼び出される。
※CentOS8ではデフォルトでは存在しないファイル。
実行結果
[yasushi-jp@centos85 ~]$ bash --login
/etc/profile start
/etc/profile.d start
/etc/profile.d end
/etc/bashrc start
/etc/bashrc end
/etc/profile end
~/.bash_profile start
~/.bashrc start
/etc/bashrc start
/etc/bashrc end
~/.bashrc end
~/.bash_profile end
[yasushi-jp@centos85 ~]$

2. Bash実行時に読み込まれる設定ファイル

読込順 ファイル1 ファイル2 ファイル3 概要
1 ~/.bashrc /etc/bashrc /etc/profile.d 「~/.bashrc」の中で「/etc/bashrc」が呼び出され、「/etc/bashrc」の中で「/etc/profile.d」配下のシェルが呼び出される。
実行結果
[yasushi-jp@centos85 ~]$ bash
~/.bashrc start
/etc/bashrc start
/etc/profile.d start
/etc/profile.d end
/etc/bashrc end
~/.bashrc end
[yasushi-jp@centos85 ~]$

以上

3
3
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
3
3