The escape character circumflex accent ('^') is working finde even after conditional execution.
But you are underestimating the consequences:
The next character is treated as no special character (by the scanner of the command line interpreter).
In your first example the next character to the scanner is the space character in the next line.
This space is now handled as a normal character (and not as a separator character).
After this character a second space character is found, which is a separator.
So the space is the first token of a single instruction which is defined as the command-
This command (" ") is unknown.
So you have to remove all characters in front of echo to make this example work:
Code: Select all
md "dir" ||^
echo Failed to make dir
(The 'e' is treated as a normal character, which is its default meaning.)
For the same reason the '(' is treated as a normal charcter.
But you cannot add seperator characters in front of the '(' to let the opening parenthesis be a special character for the above reason.
So you have to redirect stderr to nul (you don't want to see the error message 'command " " unknown', or similar) and add an ampersand to execute multiple commands:
Code: Select all
if "%x%" == "%y%" ^
2>nul & (
echo Match found.
) else (
echo Match not found.
)
Sidenote:
A "scanner"/"lexer" reads the source code lines and transforms each line into a sequence of (so called) tokens (smallest meaningful units) and is a part of an interpreter.
penpen