Loose-Info.com
Last Update 2022/06/05
TOP - 各種テスト - bash - --init-file(起動時オプション)

--init-file ファイル
--rcfile ファイル
対話型として起動させた際に、標準の初期化ファイル~/.bashrcの代わりにファイルを読み込み・実行

テスト概要

--init-file オプションの有無による読み込みファイルの違いを比較

実行環境

GNU bash, version 5.1.16


コード例・出力内容中の表記

・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。

使用ファイル

testfile
# ********** ~/testfile ここから ********** echo "[testfile]" # ********** ~/testfile ここまで **********

bash関連ファイルの設定(テスト用)

/etc/profile
# ********** /etc/profile ここから ********** echo "[etc_profile]" # ********** /etc/profile ここまで **********

~/.bash_login
# ********** ~/.bash_login ここから ********** echo "[bash_login]" # ********** ~/.bash_login ここまで **********

~/.bash_logout
# ********** ~/.bash_logout ここから ********** echo "[bash_logout]" # ********** ~/.bash_logout ここまで **********

~/.bash_profile
# ********** ~/.bash_profile ここから ********** echo "[bash_profile]" # ********** ~/.bash_profile ここまで **********

~/.bashrc
# ********** ~/.bashrc ここから ********** echo "[bashrc]" # ********** ~/.bashrc ここまで **********

~/.profile
# ********** ~/.profile ここから ********** echo "[profile]" # ********** ~/.profile ここまで **********

動作テスト


--init-fileオプションを使用せずにbashを起動
-bash-5.1$ bash [bashrc] <--- ~/.bashrcの実行による出力 bash-5.1$ exit exit -bash-5.1$

--init-fileオプションを使用し、初期化ファイルとしてtestfileを指定してbashを起動
-bash-5.1$ bash --init-file testfile [testfile] <--- testfileの実行による出力 bash-5.1$ exit exit -bash-5.1$