By Biswajyoti Roy

2019-02-09 18:08:59 8 Comments

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. My Terminal now looks like thisTerminal

My bash profile currently looks like this when i enter open .bash_profile in new command on terminalbash_profile text file

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 bash_profile after source command

After that i also run the command echo $PATH. and the result was this :bash_profile after echo $PATH. Command

I have no idea what i did. And what i need to do to fix the problem. Any help will be truly appreciated.


@bmike 2019-02-09 19:31:21

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.

@Biswajyoti Roy 2019-02-09 19:50:19

Thanks bmike.i will try to do that. My bash_profile has so so many stuff.IT will be tuff. BTW where should i put the new "export PATH="/usr/local/sbin:$PATH:$GEM_HOME/bin" in bash_profile? In the begining or in the end?

@Biswajyoti Roy 2019-02-09 19:58:29

my bash_profile is filled with so many code with PATH=".....' is it possible that i delete everything except the new line "export PATH="/usr/local/sbin:$PATH:$GEM_HOME/bin""

@Gordon Davisson 2019-02-09 20:44:37

It's also critical that you remove from the cat << EOF ... line through the EOF on a line by itself -- every time that runs, it adds another batch of garbled mess to the end of the .bash_profile itself. Frankly, I think it'll be easier to dump it, and start over (see my answer).

@Gordon Davisson 2019-02-09 20:37:57

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
# Add Visual Studio Code (code)
export PATH="$PATH:/Applications/Visual Studio"

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.

@Biswajyoti Roy 2019-02-09 20:44:34

I Have billions of code in the bash_profile.So it vary hard for me to pick & Choose. Moreover i already uninstall and deleted python3,VScode. I was wondering if i delete everything on bash and just keep this one line code "export PATH=/usr/bin:/usr/sbin:/bin:/sbin" in th bash_profile. is it posiible to fix the issue? i am in real fixing this thing quick is a big deal. later i can reinstall all the programs which should be fine? Thanks a lot again.I really Really appreciate your help

@Gordon Davisson 2019-02-09 20:47:45

Are you still using Visual Studio Code? If so, I'd keep just the last two lines of what I have above. If you're not using VS Code, just remove the .bash_profile entirely (but keep a backup, just in case). PATH should be automatically set to a reasonable (but basic) value without the file. If you do need to set it for some reason, PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin is the original default, and I'd recommend using that.

@Biswajyoti Roy 2019-02-09 20:55:06

I just deleted everything and just kept the line "export PATH=/usr/bin:/usr/sbin:/bin:/sbin" now seems like the terminal running again. I Just got this back: [braeburn:~ [username]$ echo $PATH. /usr/bin:/usr/sbin:/bin:/sbin.]

@Gordon Davisson 2019-02-09 21:02:43

That's pretty close to the standard PATH, but it's missing /usr/local/bin. I'd recommend either removing that line (leaving the default PATH), or force the standard value with export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

@Biswajyoti Roy 2019-02-09 21:05:20

BTW i removed my previous SQL path [export PATH="/usr/local/mysql/bin:$PATH"], If i want to add it again to my bash_profile (otherwise MYSQL dont run for some reason) what should be the safe code?

@Biswajyoti Roy 2019-02-09 21:11:18

Thanks. I already changed the path according to your recommendation. if you have time and can tell me how i can add the SQL code safe into bash_profile given that i deleted [export PATH="/usr/local/mysql/bin:$PATH"], i would be truly grateful. BTW applying your suggestion my new path is now [/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

@Gordon Davisson 2019-02-09 21:41:15

Adding export PATH="/usr/local/mysql/bin:$PATH" to your .bash_profile is fine. As bmike said in his answer, it's the entries that don't include $PATH on the right side that cause problems. Essentially, an entry like this adds to the PATH, while one that doesn't have $PATH on the right side is replacing the PATH (deleting all the other additions that're already there). Adding things to PATH just increases the list of places the system will look for command files, which isn't a big deal.

@bmike 2019-02-09 21:56:46

Amazingly well done Gordon. I didn’t conceive of the cat and that explains much of the mess. Thanks for reinforcing - just set it aside, add pieces in little by little. Also BBEdit - ♥️ that program so much

Related Questions

Sponsored Content

0 Answered Questions

Terminal Startup command not found

2 Answered Questions

[SOLVED] ERROR: AUCTeX cannot find a working TeX distribution (macOS Sierra)

  • 2017-03-29 08:49:30
  • Evan Aad
  • 2317 View
  • 0 Score
  • 2 Answer
  • Tags:   path emacs

1 Answered Questions

[SOLVED] Terminal Crash on Macbook Air 2011, Mavericks

0 Answered Questions

Defective Login After Failed Upgrade to macOS Sierra

1 Answered Questions

3 Answered Questions

4 Answered Questions

[SOLVED] Strange path environment

  • 2014-09-20 13:58:11
  • nbro
  • 239 View
  • 0 Score
  • 4 Answer
  • Tags:   path

0 Answered Questions

Editing $PATH variable for apache on mountain lion

2 Answered Questions

Mac Terminal PATH settings

  • 2012-08-28 12:01:59
  • Magnus
  • 3551 View
  • -1 Score
  • 2 Answer
  • Tags:   macos path terminal

Sponsored Content