zsh path "no such file or directory" where do I unset it?

superuseroi picture superuseroi · Feb 6, 2014 · Viewed 35.8k times · Source

I just noticed that my $PATH has an invalid location:

\> $PATH
zsh: no such file or directory: /usr/bin:/bin:/usr/sbin:/sbin: ...

I use prezto and according to the docs the config files are sourced in this order:

  1. /etc/zshenv
  2. ~/.zshenv
  3. /etc/zprofile
  4. ~/.zprofile
  5. /etc/zshrc
  6. ~/.zshrc
  7. ~/.zpreztorc
  8. /etc/zlogin
  9. ~/.zlogin
  10. ~/.zlogout
  11. /etc/zlogout

I checked the whole list and I can't find anything that would come before /usr/bin

Any suggestion on how I could go about finding what is triggering the issue?

Thanks!

Answer

Adaephon picture Adaephon · Feb 7, 2014

As far as I can tell there is nothing wrong with your PATH. If you want to see the content of PATH use echo:

% echo $PATH
/usr/sbin:/usr/bin:/sbin:/bin

PATH is a colon separated list of directories to search for commands. Essentially, zsh will try the name of your command with each path and execute the first find (/usr/sbin/foo, /usr/bin/foo, etc.). If any of the listed directories does not exist, there will be no error message, zsh will simply not find a binary there and try the next one.

The issue in your case is triggered by trying to execute $PATH. Before executing a command line, zsh - among other things - replaces all variables with their content, this is called Parameter Expansion (so man 1 zshexpn for more information on that).

So, when you just write $PATH, zsh replaces it with /usr/bin:/bin:/usr/sbin:/sbin:... and interpretes it as one long path. That is, : is not taken as separator but as part of the directory names. Any you are getting the same error message you would get with any other non-existent directory:

% ls /some/path
dir1 dir2
% /some/path/nothere/notthere
zsh: no such file or directory: /some/path/nothere/notthere