yakataの情報奮闘記

プログラミングの話をします

WSL2で~/.bashrcが読み込まれずに困った話と解決策

Hello WSL2

ブログ書くのは久方ぶりなので、書き方から忘れています、yakata66です。 今回はWSL2が起動時にbashrcを読み込んでくれずに困った話をしたいと思います。

今回起きたこと

自分は~/.bashrcにaliasを色々入れているのですが、それがterminalの再起動時に command not found. を引き起こして発覚しました。

環境はUbuntu20.04です。

そもそも起動時に何が起きているのか

WSL2は起動時に"~/.bash_profile", "~/.bash_login", "~/.profile"らへんが読み込まれるのですが、~/.profileの最初の五行に書いてあるとおり ~/.bash_profileや~/.bash_loginがあると、そっちを読み込んでprofileを読み込まないよって書いてます。

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

ということで~/.bash_profile は読み込まれるので、即物的な対応策としては~/.bash_profileの最後に

bash

と書いてあげると~/.bashrc が読み込まれることになります。