Just because you cannot echo %path%
does not mean your PATH is broken. The purpose of the PATH environment variable is to provide a list of folders to search for a program if you invoke a program without specifying the path.
Assuming you have MyProgram.exe
in the C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5
folder, then executing MyProgram
will correctly execute MyProgram.exe
, regardless what your current directory is.
But indeed, if you attempt to echo %path%
, then that will fail - and it should.
If you change the value in your PATH to read C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 ^& MySQL Utilities 1.5
, then sure, you can safely echo %path%
. But now if you execute MyProgram
, then MyProgram.exe
will not be found because the PATH is pointing to the wrong folder name.
An alternative that works is to modify your PATH to read "C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5"
(quote the value). Now the PATH functions properly, allowing you to execute MyProgram
from anywhere, and it is now safe to echo %path%
.
But you may not have control of all the values entered into your PATH definition. Because of the design of how PATH works, it simply is not safe to echo %path%
in all situations. In fact, it simply is not reliable to ever use %path%
in any command.
That is probably why the path
command is designed to safely print out the value of the PATH environment variable without having to do any explicit variable expansion.
Even if echo %path%
fails, executing path
will print out the correct full definition.
Another option is to enable delayed expansion and use echo !path!
. It is always safe to work with any value when you use delayed expansion.
In fact,
echo %PATH%
was not the main culprit, I am calling a lot of batch scripts from a cygwin shell and vice versa (without using%PATH%
), and sometimes it bombed me with those Could not find command MySQL... outputs where I did not expect them.echo %PATH%
was only the what I thought best way to easily reproduce the behaviour. I had tried the"
way before, but I only clicked on OK once (see my answer), so it did not work. I now tried it once again and it worked. :-) – Bowi – 2020-01-23T08:38:45.733