when I write in terminal
echo $PATHmy output is
:/home/bo/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin:/usr/bin:/sbin:/binbut when I write just :
$PATHthis 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 directoryand my question is, why did it write "No such file or directory?" every directory from PATH variable exists.
5 Answers
$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.
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 directoryThe first word of every command line has to be a command. echo 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.
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?
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.
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.