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 1 year has passed since last update.

.bash_profileに余計な記載をしてしまってMacを再起動したらターミナルというターミナルでshellが起動しなくなった

Last updated at Posted at 2024-02-21

概要

.bash_profileに「同階層に.bashrcがあったら読み込む処理」を記載したつもりがなにかよろしくない処理を書いてしまった模様で純正ターミナルアプリやVScodeのターミナルでshellが起動できずコマンド入力ができなくなってめっちゃ焦ったので対処方法を簡単にまとめておく。

対処方法

まずは落ち着こう。shellが起動していないだけでMacのOSをぶっ壊したとかではないはずである。
とりあえず.bash_profileにイケてない追記をしたことは確かで、shellが開かないためviで.bash_profileを編集する事もできない。
一見詰んでるように見えるが、2通りほど思いついた

  • VScodeで.bash_profileを開いてエディタ上で編集
  • 別PCからsshで繋いで.bash_profileを編集

まずは前者でやってみようと思う。

VScodeで.bash_profileを開き編集

  1. VScodeをフォルダを指定せずに起動する。

  2. エクスプローラーをクリックし、「フォルダーを開く」をクリックする。

    Visual_Studio_Code.png

  3. 自分のユーザー名のフォルダが表示されている状態で、特にフォルダの選択をせずに「開く」をクリックする。

    開く.png

  4. サイドバーで問題になっている.bash_profileをクリックし、開き、編集を行う。

    shun.png

  5. その後PCを再起動する。

自分の場合の原因

もはや説明不要である。下記のように誤って両ファイルに両ファイルの読み込み処理を記載してしまった。

.bash_profile
if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi
.bashrc
if [ -f ~/.bash_profile ]; then
    source ~/.bash_profile
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?