Today I noticed that my path has an entry No such file or directory at the end, which causing other problems.
My path looks like this: /home/geneorama/gems/bin:/home/geneorama/anaconda3/bin:/home/geneorama/.local/bin:/home/geneorama/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin: No such file or directory
I can't figure out what's adding it, and would like to know how to troubleshoot it.
I checked .bashrc and didn't notice any problems. The .bashrc adds anaconda and Ruby as expected.
Based on this great answer on how the PATH is set, I checked my ~/.profile file. The profile script just runs .bashrc, and adds $HOME/bin and $HOME/.local/bin to the path. Those paths are only added if they exist, and they do.
I read what I could understand of man login. This led me to check /etc/login.defs, but that looked very vanilla. I don't have any of the other files mentioned in the login help.
Any ideas how to troubleshoot where this is happening?
EDIT: Jan 11, 2021
Based on the comments I edited the question to say that I had checked ~.profile.
I also made a very simple version of ~.bashrc, rebooted, and ran bash with the debug commands. The PATH is still corrupted.
geneorama@computer:~$ bash -x ~/.bashrc
+ HISTCONTROL=ignoreboth
+ shopt -s histappend
+ HISTSIZE=9999999
+ HISTFILESIZE=999999999
+ shopt -s checkwinsize
geneorama@computer:~$ $PATH
bash: /home/geneorama/.local/bin:/home/geneorama/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin: No such file or directoryEDIT: Jan 11, 2021 (second edit today)
I also noticed that I can't fix the error by manually setting the path or by logging in as root. I tried using export and setting the path using a quoted string (I don't know if it matters or the best way).
geneorama@computer:~$ $PATH
bash: /home/geneorama/gems/bin:/home/geneorama/anaconda3/bin:/home/geneorama/.local/bin:/home/geneorama/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin: No such file or directory
geneorama@computer:~$ PATH="/home/geneorama/gems/bin:/home/geneorama/anaconda3/bin:/home/geneorama/.local/bin:/home/geneorama/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
geneorama@computer:~$ $PATH
bash: /home/geneorama/gems/bin:/home/geneorama/anaconda3/bin:/home/geneorama/.local/bin:/home/geneorama/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin: No such file or directory
geneorama@computer:~$ sudo su -
[sudo] password for geneorama:
root@ativ4-v18:~# $PATH
-bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin: No such file or directory
root@ativ4-v18:~# logout
geneorama@computer:~$ export PATH=/home/geneorama/gems/bin:/home/geneorama/anaconda3/bin:/home/geneorama/.local/bin:/home/geneorama/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
geneorama@computer:~$ $PATH
bash: /home/geneorama/gems/bin:/home/geneorama/anaconda3/bin:/home/geneorama/.local/bin:/home/geneorama/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin: No such file or directoryAlso looked in /etc/environment/ and /etc/environment.d/. The first was empty and the second had two files 90atk-adaptor.conf and 90qt-a11y.conf, but they do not seem to be affecting the path.
EDIT: Jan 11, 2021 (third edit today)
Even when I manually set my path to be just /sbin and /bin I get the error. At this point I don't understand if the error message is actually on my path or printing along with the path.
geneorama@computer:~$ export PATH=/sbin:/bin
geneorama@computer:~$ $PATH
bash: /sbin:/bin: No such file or directoryEDIT: Jan 12, 2021
Originally I was getting an error in Jekyll. Some sites said that my error was caused by spaces in $PATH. When I (improperly) printed my $PATH I thought that something was trying to add a path that I had deleted. I thought that I had uninstalled something improperly.
The spaces being printed were part of an error message, not part of the $PATH.
Apparently Jekyll was corrupted, and the solution was to apt remove it and then reinstall it.
Along the way I learned that the path variable is modified in many non-obvious ways. The answer to my question was essentially "print your $PATH correctly".
One day someone may ask "how to I debug / profile edits to my $PATH?", and someone may mark it as a duplicate. It's not a duplicate of this question. This question turned out to be "how do I print $PATH".
52 Answers
How are you displaying the $PATH? Use
echo $PATHand you should not see the error message. If you had been using something like
ls $PATHYou get such an error appended at the end.
There is nothing wrong with your PATH. But the string of directories is not a file, and if you treat it like one (trying to execute it by just typing $PATH or trying to look at it with ls $PATH, you will get the error that it is not a file.
6The problem isn't with your PATH, it's with how you're trying to display it. The first thing in a command line is the command you're running. If you just type $PATH, the shell will try to run your PATH as a command, and it's not a command -- it's a colon-delimited list of directories to look for commands in. Since there's no actual command by that name, you get an error. (And since it's looking for an executable file corresponding to that command, the error you get is "No such file or directory").
To display the value of a shell varible like PATH correctly, use e.g. echo "$PATH" (or if it might contain backslashes/escapes, use printf '%s\n' "$PATH" instead). You can sometimes omit the double-quotes around variable references, but not always, so it's safer to just get in the habit of double-quoting variable references. And I mean always, not just in echo commands. See here, here, and here for more explanation.
For PATH specifically, it's often easier to see it if it's broken up into separate directories; you can use the tr command to turn the colon delimiters into newlines. Compare these two examples:
$ echo "$PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
$ echo "$PATH" | tr ':' '\n'
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/local/games
/usr/games 1