3

I appear to have messed up my terminal (on an OSX if that matters) big time. When I try to SSH I get -bash: ssh: command not found

After working with the command suggested to me of declare -p PATH I get declare -x PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:‌​"

Now I'm lost as to what I did and how to fix it. I'm not very knowledgeable in this area and super frustrated that I clearly dabbled in something I should have left alone.

(Edit, forgot to bring over some other content) When I run PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin PS4=':${BASH_SOURCE}:$LINENO+' bash -x -l -i, The resulting output containing ~/.bash_profile is:

/Users/Name/.bash_profile:1+export PATH= /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin‌​:/opt/X11/bin} 
:/Users/Name/.bash_profile:1+PATH= bash: export: ``/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sb‌​in:/opt/X11/bin': not a valid identifier 
:/Users/Name/.bash_profile:5+PATH=/Library/Frameworks/Python‌​.framework/Versions/‌​3.6/bin: :/Users/Name/.bash_profile:6+export PATH'
3
  • 1
    If you open a new terminal, is it still broken? Jan 20, 2018 at 2:17
  • if opening a new terminal window doesn't fix it, try running ssh with the full path (since maybe you messed your path up). type it like this and hit enter: /usr/bin/ssh
    – WEBjuju
    Jan 20, 2018 at 2:21
  • No, the new terminal didn't work. When I used /usr/bin/ssh I got usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [user@]hostname [command] Jan 20, 2018 at 16:10

2 Answers 2

4

The default PATH on macOS is

PATH="/usr/bin:/bin:/usr/sbin:/sbin"

If you run that in your terminal, you'll be back to normal.

If you've modified your .bashrc file, or similar, to add or change a line like that, remove it, or change it to

PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:‌​$PATH"

Note in particular that there is not a space after PATH=; it’s all run together, and if you’ve made a change yours should be structured the same way. If you didn't, you can also just reopen your terminal and everything will be fine.

3
  • From prior discussion with this user on a StackOverflow iteration of this question, I believe they're updating their path in .bash_profile. Unfortunately, I wasn't able to get them to edit the relevant content into the question, vs posting it in a comment, so the details are a bit hard to follow; see stackoverflow.com/questions/48103099/… Jan 20, 2018 at 5:57
  • Sorry about that, I have added the output above. Let me know if there was something else I needed to add. Jan 20, 2018 at 16:19
  • 1
    @walkingbytrees You need to take the space out after PATH=. Jan 20, 2018 at 19:13
2

Your .bash_profile appears to contain:

export PATH= /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin‌​:/opt/X11/bin}

This has two problems:

  • The space after the = and before the value causes the value to be a separate argument to export, not part of the new value of PATH. Thus, what export sees is PATH= (setting the PATH to an empty string), and /usr/local/sbin:... (which isn't an assignment at all, and is thus ignored).
  • The closing } is surely not desired.

Thus, you should modify the file to instead contain:

export PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin‌​:/opt/X11/bin

...or, more simply:

PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin‌​:/opt/X11/bin

...as export is not needed here: Because PATH is already in the environment, updates are always exported automatically.

1
  • Thanks! That fixed it. Not sure how the space got in there. I tested it out and everything seems in working order! Jan 22, 2018 at 13:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .