How can I fix my terminal when editing the PATH in .bash_profile has the startup hang and I get no prompt?
I am new to the command line and clearly messed up my setup.
- macOS High Sierra(10.13.6)
- Trying to set up Python and VScode.
My path variable is what I believe is wrong, but Idon't know exactly how to get a shell and fix things.
It is now showing the user name when i go into terminal. After trying everything i tried to follow. https://shellzero.wordpress.com/tag/reset-path-on-mac/ My Terminal now looks like this
My bash profile currently looks like this when i enter open .bash_profile
in new command on terminal
according to the suggestion of the article mentioned above, after entering export PATH=/usr/bin:/usr/sbin:/bin:/sbin
and save the text file by command+S
I tried to execute source ~/.bash_profile
in new command in terminal and the result was
After that i also run the command echo $PATH.
and the result was this :
I have no idea what i did. And what i need to do to fix the problem. Any help will be truly appreciated.
Solution 1:
OK - no worries. You did in fact mess things up, but here's an easy way to fix things.
- Open TextEdit (or whatever editor you like graphically on the Mac)
- Open a file and go to your home folder (click or press Command Shift G and type ~ and return)
- Show hidden files (if needed) - Command + Shift + .
- Open .bash_profile
Delete everything or comment out anything that contains PATH= and save the file (you can save as to save it to your Desktop if you want to fix it up rather than start new).
Then open a new terminal window to check your work. If it works, close out the broken sessions and make sure you incorporate the old path when you add things:
This is safe:
export PATH="/usr/local/sbin:$PATH:/path/to/whatever/bin"
It's safe since the old $PATH is included on the right of the =
What isn't safe is when
export PATH="whatever"
All the other parts of the path are now gone, with only whatever left and the last = wins, so your path is missing very important items instead of adding things to the default path, you broke it temporarily. No worries, this is a phase of passage - everyone needs to break their shell dot files to learn. Welcome to the club.
Solution 2:
I'd recommend a somewhat different approach from @bmike: rather than trying to remove the bad parts from the current file, start over and add back just the good parts. It looks like there's a lot more bad than good in the current file, so this should be simpler.
What's really really really bad in the current file is the section that starts like this:
cat << EOF >> ~/.bash_profile
...and somewhere down below that there'll be EOF
alone on a line. The problem is that this isn't an instruction to set up your environment, it's instructions to add instructions to your ~/.bash_profile. In other words, every time your ~/.bash_profile runs, it adds another copy of the stuff between cat
and EOF
to the end of ~/.bash_profile, so the file gets longer and longer and longer... and has more and more copies of the messed up instructions.
At this point, your ~/.bash_profile will be huge, and mostly garbled nonsense.
So, I recommend starting over. Rename and save the current file, so you can refer back to it if necessary, then create a new blank .bash_profile in your home directory. I recommend BBEdit for this -- it has a free demo mode that'll do everything you need here, and (unlike most text editors) it won't do "helpful" things like converting plain ASCII quotes (like "
) to fancy unicode quotes (like “
and ”
) that mess up shell scripts. It also doesn't complain about saving files with names that start with ".".
From the section visible in your screenshot, this is the only part of the current file that looks right:
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
# Add Visual Studio Code (code)
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
There might be something you actually want further down, but since the cat
part starts shortly after that I doubt it. In any case, this should be enough to get you a basically functional setup; if there are some things that still don't work, you may have to look through the old file for other things that need salvaging.