Skip to content

Instantly share code, notes, and snippets.

@10sr
Last active February 24, 2020 15:31
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 10sr/667c006e40dc33ff651d to your computer and use it in GitHub Desktop.
Save 10sr/667c006e40dc33ff651d to your computer and use it in GitHub Desktop.
.profile, .bashrc, .bash_profile... どこに何を書くか

https://github.com/10sr/dotfiles

Porpose

設定を書く場所を集約したい

Problem

例えば、 .profile に何かを書いたとして、その後 .bash_profile が生成された場合、 bash 起動時に .profile は読まれなくなってしまう、みたいな。

.bashrc を .bash_profile から読むか .profile から読むか?

What Should I Do?

  • .profile: ログイン設定
  • .bash_profile: bash 固有のログイン設定
    • .profile を読むべき
    • ログイン時には .bash_profile が読まれ、 .bashrc は読まれない
      • .bashrc_profile は explicit に .bashrc を読むべき
  • .shrc: 対話シェル用の設定
  • .bashrc: bash 用の対話シェル設定
    • .shrc を読むべき

Sourcing Flow

$HOME/{.bash_profile,.zprofile}  <= login with bash/zsh
| |
`---$HOME/.profile                <= login with sh
  |   |
  `---|--$HOME/.{ba,z}shrc          <= bash, zsh
      |  |
      `--`--$HOME/.shrc             <= sh (by EnvVal ENV)

* .profile should load .shrc unless bash nor zsh is working
  • Login with sh

    1. .profile
    2. .shrc
  • Login with bash

    1. .bash_profile
    2. .profile
    3. .bashrc (from .bash_profile)
    4. .shrc
  • Non-login with bash

    1. .bashrc
    2. .shrc

So, What Should I Have?

  • .profile

    • General setups for login
    • 環境変数など
  • .bash_profile

    • bash-specific setups for login
    • なんだろう? bash 固有で使いたい環境変数とか
. ~/.profile || true
. ~/.bashrc || true
  • .shrc

    • General setups for interactive shell
    • よくやるやつ。関数とか alias とか
  • .bashrc

    • bash-specific setups for interactive shell
    • bash 固有の alias とか補完とか
. ~/.shrc || true

For Example

bash を使ってる時、

  • .bash_profile. ~/.profile
  • .bash_profile. ~/.bashrc
  • .bashrc. ~/.shrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment