Linux環境設定/.bashrcと.bash_profileの違い
の編集
Top
/
Linux環境設定
/
.bashrcと.bash_profileの違い
[
トップ
] [
編集
|
差分
|
バックアップ
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
(no template pages)
#navi(../) * .bashrcと.bash_profileの違い [#fad70880] Linuxの標準シェルとして採用されているbash(Bourne Again Shell)ですが設定ファイルとして以下の2つがあります。 -.bash_profile -.bashrc この2つの違い(使い方)について、以下に記述します。 #contents #htmlinsertpcsp(linux_ads_top.html,linux-sp.html) * 関連記事 [#z70ee4b5] -[[bashで前回入力したキーワードを置換し再実行する方法>逆引きUNIXコマンド/bashで前回入力したキーワードを置換し再実行する方法]] -[[bashシェルでTABキーを押してホスト名の補完する>逆引きUNIXコマンド/bashシェルでTABキーを押してホスト名の補完する]] * .bashrcと.bash_profileの説明 [#eb4c04c1] |.bashrc|bashを起動するたびに実行されます| |.bash_profile|ログイン時に一度実行されます| ** 実験 [#f92de640] CentOSでは以下のように.bashrc, .bash_profileが記述されています。 *** .bashrc [#bbd104ac] # .bashrc # Source global definitions~ if [ -f /etc/bashrc ]; then~ . /etc/bashrc~ fi~ # User specific aliases and functions *** .bash_profile [#e4351b54] # .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 以下のように編集してテストしてみます。 *** .bashrc編集版 [#b065a38d] 読み込まれた時、''Read .bashrc''と表示します。 # .bashrc~ &color(red){echo "Read .bashrc"};~ # Source global definitions~ if [ -f /etc/bashrc ]; then~ . /etc/bashrc~ fi~ # User specific aliases and functions *** .bash_profile編集版 [#ga6530bc] 読み込まれた時、''Read .bash_profile''と表示します。~ また環境変数TESTを設定してあります。 # .bash_profile~ &color(red){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~ &color(red){export TEST=sakura};~ export PATH +GUIのログイン後、ターミナルを起動した場合~ Read .bash_profileと出力されていませんが、GUIによるログイン時に.bash_profileが動作しTEST=sakuraが設定されてることが確認できます。 #ref(bash-profile-01.gif) #br +ターミナルアイコンをクリックして起動した場合~ Read .bashrcのみが表示されます。つまり、.bash_profileは読み込まれていません。 #ref(bash-profile-02.gif) #br +sshにて接続しログインしてみる~ Read .bash_profile, Read .bashrcの両方が表示されます。~ つまり、ログイン時は.bash_profileが読み込まれていることが確認できました。~ .bash_profileの以下の構文により.bashrcが読み込まれ反映されます。~ # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi #ref(bash-profile-03.gif) #htmlinsertpcsp(linux_ads_btm.html,linux-sp.html) #br
タイムスタンプを変更しない
#navi(../) * .bashrcと.bash_profileの違い [#fad70880] Linuxの標準シェルとして採用されているbash(Bourne Again Shell)ですが設定ファイルとして以下の2つがあります。 -.bash_profile -.bashrc この2つの違い(使い方)について、以下に記述します。 #contents #htmlinsertpcsp(linux_ads_top.html,linux-sp.html) * 関連記事 [#z70ee4b5] -[[bashで前回入力したキーワードを置換し再実行する方法>逆引きUNIXコマンド/bashで前回入力したキーワードを置換し再実行する方法]] -[[bashシェルでTABキーを押してホスト名の補完する>逆引きUNIXコマンド/bashシェルでTABキーを押してホスト名の補完する]] * .bashrcと.bash_profileの説明 [#eb4c04c1] |.bashrc|bashを起動するたびに実行されます| |.bash_profile|ログイン時に一度実行されます| ** 実験 [#f92de640] CentOSでは以下のように.bashrc, .bash_profileが記述されています。 *** .bashrc [#bbd104ac] # .bashrc # Source global definitions~ if [ -f /etc/bashrc ]; then~ . /etc/bashrc~ fi~ # User specific aliases and functions *** .bash_profile [#e4351b54] # .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 以下のように編集してテストしてみます。 *** .bashrc編集版 [#b065a38d] 読み込まれた時、''Read .bashrc''と表示します。 # .bashrc~ &color(red){echo "Read .bashrc"};~ # Source global definitions~ if [ -f /etc/bashrc ]; then~ . /etc/bashrc~ fi~ # User specific aliases and functions *** .bash_profile編集版 [#ga6530bc] 読み込まれた時、''Read .bash_profile''と表示します。~ また環境変数TESTを設定してあります。 # .bash_profile~ &color(red){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~ &color(red){export TEST=sakura};~ export PATH +GUIのログイン後、ターミナルを起動した場合~ Read .bash_profileと出力されていませんが、GUIによるログイン時に.bash_profileが動作しTEST=sakuraが設定されてることが確認できます。 #ref(bash-profile-01.gif) #br +ターミナルアイコンをクリックして起動した場合~ Read .bashrcのみが表示されます。つまり、.bash_profileは読み込まれていません。 #ref(bash-profile-02.gif) #br +sshにて接続しログインしてみる~ Read .bash_profile, Read .bashrcの両方が表示されます。~ つまり、ログイン時は.bash_profileが読み込まれていることが確認できました。~ .bash_profileの以下の構文により.bashrcが読み込まれ反映されます。~ # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi #ref(bash-profile-03.gif) #htmlinsertpcsp(linux_ads_btm.html,linux-sp.html) #br
テキスト整形のルールを表示する
添付ファイル:
bash-profile-02.gif
635件
[
詳細
]
bash-profile-03.gif
631件
[
詳細
]
bash-profile-01.gif
641件
[
詳細
]