Here's a simple but puzzling question.
For an undefined Windows environment variable, abc for example
In the Command Prompt window ECHO [%abc%] results in [%abc%]
But in a .CMD batch file ECHO [%abc%] results in []
Why the difference? I've researched the ECHO command and can't find anything about this. I'm concerned about where else this subtle difference might apply.
Environment variables store data that is used by the operating system and other programs. For example, the WINDIR environment variable contains the location of the Windows installation directory. Programs can query the value of this variable to determine where Windows operating system files are located.
Environment variables help programs know what directory to install files in, where to store temporary files, and where to find user profile settings. They help shape the environment that the programs on your computer use to run.
However, setting some environment variables makes some things easier. PATH If the jre/bin folder is on the path, you don't have to qualify to run the java command. If the jdk/bin folder is on the path, you don't have to qualify to run the java and javac commands. As well as some other commands provided by Java.
Really good question! Confusing huh?
There are actually two distinct parsers used to parse batch scripts and command line commands.
Quote from this excellent answer:
BatchLineParser
- The parser inside of batch files, for lines or blocks
CmdLineParser
- Like theBatchLineParser
, but directly at the command prompt, works different
The key difference is in the first phase of parsing, particularly the extension of %var%
:
In BatchLineParser
if var
does not exists will be replaced with nothing, in CmdLineParser
if the var
isn't defined, the expression will be unchanged.
So why did someone design it this way? I have absolutely no idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With