25

Amazon Linux Server, connected with SSH:

I tried to change the PATH for the apache user by making some changes in /etc/environment (PATH=$PATH:/opt/openoffice4/program) and /etc/sysconfig/httpd (export PATH = ${PATH:$PATH:}/opt/openoffice4/program).

Then I rebooted.

Now, I can not do anything, even ls -l leads to -bash: ls: command not found

What can I do to regain control?

3
  • 4
    Can you run commands directly? For example /bin/ls?
    – DavidPostill
    Nov 13, 2015 at 10:13
  • yes, I can run /bin/ls
    – Lokomotywa
    Nov 13, 2015 at 10:14
  • 13
    Then you should be able to run /bin/vi and fix the files where you broke the path.
    – DavidPostill
    Nov 13, 2015 at 10:15

3 Answers 3

48

What can I do to regain control?

Run /bin/vi and revert the changes you made to /etc/environment and /etc/sysconfig/httpd .

31

You can set your PATH without an editor. Just type this in the shell:

export PATH=/usr/local/bin:/usr/bin:/bin:$HOME/bin
4
  • 1
    And remove the spaces! PATH=something, NOT PATH = something
    – waltinator
    Nov 13, 2015 at 21:46
  • 4
    That ought to be quoted, or else $HOME will be subject to globbing and word-splitting. IOW, it will break if $HOME has a space in it (plausible) or any glob characters (less likely).
    – Kevin
    Nov 13, 2015 at 22:22
  • @Kevin I tried it and the spaces and globs were just copied. (Writing export PATH=/path to home/bin doesn't work, of course.)
    – Neil
    Nov 14, 2015 at 1:34
  • 2
    @Kevin That's how it behaves in strictly conforming implementations, but at least bash gives export custom syntax rules which don't have that problem. (Custom syntax rules were already required for other reasons, e.g. to allow export array=(1 2 3).)
    – hvd
    Nov 14, 2015 at 9:29
-1

Maybe this would help:

export PATH=/usr/local/bin:/usr/bin:/bin:$HOME/bin

The 'export' command isn't used from /usr/bin, so that's why it still works!

1
  • 1
    This answer has already been suggested.
    – xenoid
    Aug 29, 2017 at 23:23

You must log in to answer this question.

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