0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

.bashrcと.bash_profileの違い

Posted at

.bashrc/.bash_profile/.profile それぞれに何を書くのか

  • ~/.bash_profile
    -> 余計なものを書かない。
    ログイン時に一回だけ実行する設定を書く
    .profileと.bashrcを読み込む設定だけ書く

  • ~/.bashrc
    シェルを起動するたびに実行したい設定を書く
    ex.) EDITOR変数, プロンプト設定

  • ~/.profile
    bashに依存しないものを書く
    ex.) 環境変数, GUI設定

上記を踏まえての設定

.bash_profile
# .profileを読み込む
if [ -f ~/.profile ] ; then
. ~/.profile
fi
# .bashrcを読み込む
if [ -f ~/.bashrc ] ; then
. ~/.bashrc
fi
.bashrc
# gitのブランチ名と改行
source /usr/local/etc/bash_completion.d/git-prompt.sh
source /usr/local/etc/bash_completion.d/git-completion.bash
# default:cyan / root:red
if [ $UID -eq 0 ]; then
    PS1='\[\033[31m\]\[\033[00m\]\[\033[01m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\n\$ '
else
    PS1='\[\033[36m\]\[\033[00m\]\[\033[01m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\n\$ '
fi
.profile
# rubyの環境変数設定
export PATH=$HOME/.nodebrew/current/bin:$PATH
eval "$(rbenv init -)"

参照

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?