0

I've got a pretty big issue right now, I've tried setting a PATH to a python file, but I've done it wrong and seemingly broken every command on debian.

What I get when I type any command:

-bash: "command": No such file or directory

I think this might have happened when I just typed "PATH=" with nothing after the equal sign. How can I reset this?

1 Answer 1

2

If you are doing this in a graphical X session (which is likely), you can simply close the terminal window and open a new one. Because the change to $PATH doesn't get promoted to the parent process, the new terminal session will inherit the correct value for $PATH from its parent process, and bash will apply any further customization from the configuration on disk.

If you aren't running in an X session, then the easiest solution is probably just to log out and back on. Unless you made changes to your bashrc or bash profile files, that will reset your $PATH to its normal value.

If for some reason you are having difficulty logging out, you can at the bash prompt just hit Ctrl+C to tell the shell to ignore any input on the current command line, followed by Ctrl+D. The latter sends an end-of-file signal to the shell, which causes it to exit. If your login shell exits, you are brought back to the login prompt and can log back on.

If you aren't running through X and cannot log out right now then you can start a new login shell, which will set up its own copy of the environment, including $PATH. This may be useful if you are in the middle of something and want to get to a point where you can cleanly exit and then continue. To do this, you need to run bash with the --login (or -l) parameter. Since bash won't be in your $PATH, you need to specify the full path to it. Thankfully this is pretty easy, because pretty much every modern system which has bash installed will have it at /bin/bash, so we know where to look.

  • First run exec /bin/bash --login. This will replace your current shell with a new one, which will have mostly the correct environment. However, it's possible that your bash startup scripts rely on things which aren't available because $PATH is empty. If this is the case, it's highly likely that they will print a few (or many) errors.
  • To get around that, just exec /bin/bash --login again. This should be executing in an environment where $PATH is set correctly, so the bash startup scripts will be able to run what they need. The result will be a correctly set up shell instance.

You don't really need to use exec, but it's handy here because it causes your existing shell to be replaced by the new one as opposed to simply launching the new instance as a subprocess. If you don't use exec in this situation, when you exit the most recently started shell, you'll be back in the broken instance.

You must log in to answer this question.

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