In Cygwin, why does echo $PATH work, but $PATH fail?

1

As seen here, doing echo $PATH gives me my full PATH, but doing simply $PATH gives an incomplete version that looks like it hasn't been escaped properly somewhere:

enter image description here

Yet when I look into my configuration files, the only relevant lines for the PATH seem to be:

PATH=$PATH

...in .bashrc, and...

export PATH=usr/local/sbin:/usr/sbin:$PATH
export PATH=/sbin:$PATH
export PATH=/cygdrive/b/users/me/desktop:$PATH

...in .bash_profile. Both seem correctly formatted to me, so I'm unsure what's going on here. Can anyone else shed some light on it?

Hashim

Posted 2018-09-08T00:44:10.203

Reputation: 6 967

1Generally, the first thing on the command line should be a command name (well, or an assignment). $PATH is a variable... that doesn't contain a valid command name. So running $PATH as a command is not really expected to do anything particularly sane. – Gordon Davisson – 2018-09-08T01:06:10.570

Answers

2

(I assume you deleted your username from between users/ and /desktop. It now looks like few spaces, but in fact there is no space there.)

When you invoke sole $PATH, the first space in it separates what bash interprets as a command from its first argument. No such file or directory refers to the "command".

The first space is in Program Files, therefore the "command" ends with Program. It fails because there's no such file.

Kamil Maciorowski

Posted 2018-09-08T00:44:10.203

Reputation: 38 429

2

PATH is a variable (that is used by the shell to try and locate programs by looking in each of it's directories.)

When you run echo $PATH you are showing the contents if it.

When you run $PATH you are attempting to run the command included in the variable. As this is a list of directories, it's not a valid command do it produces the error.

davidgo

Posted 2018-09-08T00:44:10.203

Reputation: 49 152