0

Consider the following Windows batch script:

@echo off
echo Here 1
rem %~ta
echo Here 2...but not displayed as an error occurs

When executed the following is displayed:

Here 1
The following usage of the path operator in batch-parameter
substitution is invalid: %~ta


For valid formats type CALL /? or FOR /?
The syntax of the command is incorrect.

Change the %~ta line to rem test and the script completes.

The problematic line is commented out...why does it produce an error?

AlainD
  • 5,413
  • 6
  • 45
  • 99
  • 2
    Batch is evaluating the line, then executing it. Th error occurs in the evaluation phase. – Magoo Apr 25 '23 at 15:57
  • Is this similar to the preprocessor in C/C++ in that there is a hidden substitution/evaluation step? – AlainD Apr 25 '23 at 16:03
  • 1
    I recommend to read [How does the Windows Command Interpreter (CMD.EXE) parse scripts?](https://stackoverflow.com/questions/4094699/) – Mofi Apr 25 '23 at 16:43
  • @Mofi: Thanks! That's a chunky read. I hadn't realised there were so many steps involved before the command is even executed. Could you knock up an answer along the lines of "Even though the line is commented out, it is evaluated by the command line parser before execution which causes the error. See this answer for further details"? – AlainD Apr 25 '23 at 16:52

0 Answers0