ログインシェルと非ログインシェルの間で読み取られるconfファイルは何ですか?

ログインシェルと非ログインシェルの間で読み取られるconfファイルは何ですか?

探してみる.bash_profileと、、、。.bashrc.bash_login.profile

その間の読み取り順序は何ですか?

ベストアンサー1

デフォルトではログインシェルであれば/etc/profile取得します.bash_profile。ログインシェルではありませんが、端末に存在する場合は取得/etc/bash.bashrcします.bashrc

しかし、実際にははるかに複雑です。

マンページを読む方法は次のとおりです。

if bash_mode; then
    if login_shell; then
        if test -e /etc/profile; then source /etc/profile; fi
        if test -e .bash_profile; then source .bash_profile
        elif test -e .bash_login; then source .bash_login
        elif test -e .profile; then source .profile; fi
    elif interactive_shell || remote_shell; then
        if test -e /etc/bash.bashrc; then source /etc/bash.bashrc
        if test -e .bashrc; then source .bashrc; fi
    elif test -n "$BASH_ENV"; then
        source "$BASH_ENV"
    fi
elif sh_mode; then
    if login_shell; then
        if test -e /etc/profile; then source /etc/profile; fi
        if test -e .profile; then source .profile; fi
    elif interactive_shell; then
         if test -n "$ENV"; then
             source "$ENV"
         fi
    fi
fi

-bashシェルが(マイナス記号を参照)またはオプションで実行されるたびに-lログインシェルです。これは通常、コマンド(Linux仮想コンソールが実行する)を使用した場合、sshを介してログインしたり、login端末エミュレータで「login shell」オプションが有効になっている場合に発生します。

標準入力が端末であるか、-ibashがこのオプションで始まる場合は対話型シェルです。シェルがログインシェルでもある場合、bashはシェルが対話型かどうかを確認しません。したがって、.bash_profile通常はソースコードが含まれているため、.bashrc対話型シェルとログインシェル間で同じ設定を共有できます。

おすすめ記事