3

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 directory

EDIT: 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 directory

Also 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 directory

EDIT: 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".

5
  • Look in your .profile for PATH modifications.
    – ubfan1
    Jan 9, 2021 at 0:32
  • Debug via bash -x ~/.bashrc.
    – waltinator
    Jan 9, 2021 at 0:34
  • @ubfan1 I edited my question. I had checked the .profile, but I typed the wrong filename. Had some distractions while trying to write the question.
    – geneorama
    Jan 11, 2021 at 17:58
  • @waltinator thank you. I followed your suggestion and edited my question.
    – geneorama
    Jan 11, 2021 at 18:13
  • If you're going to downvote the question, please let me know why. I did my best to understand the issue and document it. Although it turned out to be a confusing error message resulting from an improper echo.
    – geneorama
    Jan 12, 2021 at 17:22

2 Answers 2

6

The 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
  • Thank you. I have accepted your answer and added notes to my question, which is much too verbose. In following the Stack Exchange rules I think we often end up with questions that are overly verbose, but that meta conversation is beyond the scope of this discussion.
    – geneorama
    Jan 12, 2021 at 17:35
4

How are you displaying the $PATH? Use

echo $PATH

and you should not see the error message. If you had been using something like

ls $PATH

You 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.

6
  • Yes, echo does not show the error, but ls $PATH does. I was typing $PATH to view the path. Also, thank you for your comments.
    – geneorama
    Jan 11, 2021 at 18:15
  • The problem is that certain Ruby commands won't run if $PATH has spaces. This was working last week, but now it's not. I didn't manually edit my path or change my .bashrc. All I've done was run some Ruby / Jekyll / Bundler commands.
    – geneorama
    Jan 11, 2021 at 20:03
  • 4
    @geneorama 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. You need to use an actual command, like echo. BTW, you should also quote variable names: echo "$PATH" instead of just echo $PATH (see this stackoverflow question). Jan 11, 2021 at 20:55
  • @GordonDavisson This should be the answer, not just a comment. I didn't think that $PATH would run as a command... normally you need to put . in front of something for it to be a command.
    – geneorama
    Jan 11, 2021 at 22:19
  • 1
    @geneorama IMO it's much easier to just get in the habit of double-quoting variable references than it is to try to remember where it's safe to leave them off. There are a few places where you need to leave them off, but that's a much shorter list and easier to remember. Jan 12, 2021 at 5:51

You must log in to answer this question.

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