2
1

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で複数の設定を読み込ませる

Posted at

.bashrcや.bash_profileにいろいろな設定が混ざっているのが嫌なので、.bashrcの末尾に以下のようにして設定ファイルを読み込ませるようにする。

...

if [ -d "$HOME/.config/bash/rc.d" ] ; then
    . $HOME/.config/bash/rc.d/*
fi

.bash_profileには以下。必要があれば.profileの読み込みを先頭でやる。

if [ -f "$HOME/.profile" ] ; then
    . "$HOME/.profile"
fi
if [ -d "$HOME/.config/bash/profile.d" ] ; then
    . $HOME/.config/bash/profile.d/*
fi

あとは設定したディレクトリにスクリプトを置いて再読み込みすればよい。
ファイル名の昇順で読み込まれるので読み込むファイル名は気を付ける。

source ~/.bashrc

おまけ

Ubuntu18.04の.profileはこのようになっている。

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi
 
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?