11

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.

18

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

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.

1

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?

  • 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. – iDrwish Feb 15 at 15:49
0

On Linux the terminal is waiting for a command, $PATH is not a command , is a variable.

When you write echo $PATH you're asking the contents of the variable and with the command echo showing it on screen.

0

The variable $PATH contains multiple directories separated by colons. The shell is expecting an executable file or other command (e.g., a shell built-in command, like cd) as input. Commands such as ls and cat are just executables located in one of the $PATH directories. Multiple directories chained together by colons generally do not form a proper UNIX file path. Notice: if you enter just one of the directories without the colon, then you get a different output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.