1
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.

【Linux】 WSL2 Ubuntu20.04 で一般ユーザの.bashrcをrootユーザでも読み込む方法

Posted at

開発環境

・ホストOS: windows10 Home
・ゲストOS: wsl2 Ubnutu20.04

問題・困ったこと

コンテナの権限周りの問題を手っ取り早く解決するためにwslのデフォルトユーザをrootユーザに変更した。
そうしたら/home/$USER/.bashrcに書き込んだ設定(主にエイリアス)が使えなくなった。

コピペして/root/.bashrcに同じ設定を書き込めばいいといえばそうなんだができれば$USERの設定をそのまま使いたい。

実現したいこと

/home/$USER/.bashrcの設定を /root/.bashrcに読み込み、設定を反映させる

実装方法

実装方法はいたって簡単で 以下の処理を/root/.bashrcに書き込めばok
(記述場所についてはどうするがよいか不明。僕はとりあえず最初に書き込んだ)

source /home/$USER/.bashrc

注: sourceコマンドは引数で指定したスクリプトを実行するコマンド

補足

一般ユーザの設定をrootユーザでも読み込むと不具合が起こりそうでちょっと怖い
仮にエラーになったらおとなしく/root/.bashrcに設定を書くか、エイリアス記述専用のスクリプトを作って読み込もうと思う

1
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
1
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?