IF Evaluation Values Are ECHO-Suppressed When Beginning With Colon ":". Why?
Posted: 17 May 2024 17:58
In my debugging of IF statements, I've noticed that the evaluation equation is ECHO-suppressed sometimes so that the echoed IF statement doesn't reveal the values being compared, obviously impeding the intended debugging. So far, I've localized this phenomenon to equations where the resulting equation begins with a colon (:) character. I haven't identified if this happens with any other character.
Note: I'm not referring to values being suppressed using the ECHO command. I'm referring to the echoed IF statements when command ECHO is ON: they're missing only the resulting equation when that equation begins with a colon (:) character, either hard-coded or as a variable (not shown since it's irrelevant).
Here's the example batch file I used (name it anything.bat or .cmd):
I'm using "@FOR %%$ in ($)do " to see the resulting IF evaluation ECHOed in batch. One can omit that part when testing the IF commands directly at the command prompt.
Output:
In my examples, I did intentionally include a few with no token delimiter after the "IF" command, having noticed that "IF(" is acceptable syntax but "IF:" is not, instead resulting in a filename ... syntax error. I'm minorly curious about this error too--why it's being interpreted as some invalid filename, but the main issue...
My question: Why would this be a thing? It just seems so random that leading the equation with a colon suppresses the equation itself from being ECHOed, but I'm wondering if I'm missing some hidden purpose to this behavior, and (even better) if there's a way to stop it and always display the equation when ECHO is ON.
Note: I'm not referring to values being suppressed using the ECHO command. I'm referring to the echoed IF statements when command ECHO is ON: they're missing only the resulting equation when that equation begins with a colon (:) character, either hard-coded or as a variable (not shown since it's irrelevant).
Here's the example batch file I used (name it anything.bat or .cmd):
Code: Select all
@FOR %%$ in ($)do IF :0==:0 ECHO/[Evaluation SUPPRESSED, true]
@FOR %%$ in ($)do IF :0==10 ECHO/[Evaluation SUPPRESSED, false]
@FOR %%$ in ($)do IF 0==:10 ECHO/[Evaluation printed, false]
@FOR %%$ in ($)do IF 0==0 ECHO/[Evaluation printed, true]
@FOR %%$ in ($)do IF(0)==(0) ECHO/[Evaluation printed, true]
@FOR %%$ in ($)do IF (0==(0 ECHO/[Evaluation printed, true]
@FOR %%$ in ($)do IF :0:==:0: ECHO/[Evaluation SUPPRESSED, true]
@FOR %%$ in ($)do IF:0:==:0: ECHO/[Evaluation printed, error] The filename, directory name, or volume label syntax is incorrect.
@FOR %%$ in ($)do IF 0:==0: ECHO/[Evaluation printed, true]
Output:
Code: Select all
C:\Test>IF ECHO/[Evaluation SUPPRESSED, true]
[Evaluation SUPPRESSED, true]
C:\Test>IF ECHO/[Evaluation SUPPRESSED, false]
C:\Test>IF 0 == :10 ECHO/[Evaluation printed, false]
C:\Test>IF 0 == 0 ECHO/[Evaluation printed, true]
[Evaluation printed, true]
C:\Test>IF (0) == (0) ECHO/[Evaluation printed, true]
[Evaluation printed, true]
C:\Test>IF (0 == (0 ECHO/[Evaluation printed, true]
[Evaluation printed, true]
C:\Test>IF ECHO/[Evaluation SUPPRESSED, true]
[Evaluation SUPPRESSED, true]
C:\Test>IF:0:==:0: ECHO/[Evaluation printed, error] The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
C:\Test>IF 0: == 0: ECHO/[Evaluation printed, true]
[Evaluation printed, true]
My question: Why would this be a thing? It just seems so random that leading the equation with a colon suppresses the equation itself from being ECHOed, but I'm wondering if I'm missing some hidden purpose to this behavior, and (even better) if there's a way to stop it and always display the equation when ECHO is ON.