No such file or directory after typing $PATH in terminal

36,658

Solution 1

$PATH is a variable, which I am sure you're aware of. When that variable is resolved, it would be the same as typing in :/home/bo/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin:/usr/bin:/sbin:/bin: and expecting something to happen. The reason echo $PATH works is because you're explicitly piping it out to the display rather than telling the terminal to "do" $PATH.

Solution 2

In case you still don't get it from the other answers, it's the same as this:

$ echo the quick brown fox
the quick brown fox
$ the quick brown fox
bash: the: command not found

$ echo and/or the black and white cats
and/or the black and white cats
$ and/or the black and white cats
bash: and/or: No such file or directory

The first word of every command line has to be a commandecho is such a command.  the, and/or, and :/home/bo/bin:/usr/local/bin:/usr/sbin… are not.  And, apparently, when you type a command line that begins with a word that isn't a command, bash says No such file or directory if the word contains one or more / characters, and command not found if it doesn't.

Solution 3

By typing

$PATH

you are actually doing nothing else than expanding its content at command line:

:/home/bo/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin:/usr/bin:/sbin:/bin

and this is not a valid command, legitimately leading to the message you are getting.

What did you expect that typing only $PATH will do?

Share:
36,658

Related videos on Youtube

wair92
Author by

wair92

Updated on September 18, 2022

Comments

  • wair92
    wair92 over 1 year

    when I write in terminal

    echo $PATH
    

    my output is

    :/home/bo/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin:/usr/bin:/sbin:/bin
    

    but when I write just :

    $PATH
    

    this output I do not understand right, output is:

    bash: :/home/bo/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin:/usr/bin:/sbin:/bin: No such file or directory
    

    and my question is, why did it write "No such file or directory?" every directory from PATH variable exists.

  • iDrwish
    iDrwish over 5 years
    I guess the expectation that $PATH would essentially print the variable to the screen without trying to execute it, however, this is not the case.