Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2870

bashrcで複数の設定を読み込ませる

$
0
0

.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 bashif[-n"$BASH_VERSION"];then# include .bashrc if it existsif[-f"$HOME/.bashrc"];then."$HOME/.bashrc"fi
fi# set PATH so it includes user's private bin if it existsif[-d"$HOME/bin"];then
    PATH="$HOME/bin:$PATH"fi# set PATH so it includes user's private bin if it existsif[-d"$HOME/.local/bin"];then
    PATH="$HOME/.local/bin:$PATH"fi

Viewing all articles
Browse latest Browse all 2870

Trending Articles