I'm running this command on a batch file:
for %I in (*.txt *.doc) do copy %I c:\test2
...and it keeps returning:
I was unexpected at this time.
What is the cause of this error?
I'm running this command on a batch file:
for %I in (*.txt *.doc) do copy %I c:\test2
...and it keeps returning:
I was unexpected at this time.
What is the cause of this error?
If you're running within a batch/cmd file, you need to double the %
markers:
for %%i in (*.txt *.doc) do copy %%i c:\test2
The single %
variant only works from the command line.
If being run from a batch file, variables need to be denoted with two percent signs, like %%I
, only from the command line you use one
I ran across a case where I was getting this error from a file that was named *.cmd. The error arose when I tried to access the first argument to the batch command:
if %1 EQU ""
Once I put quotes around the symbol for the first argument, the warning message went away:
if "%1" EQU ""
Not a direct answer to the question, but if you encounter this message in any program, batch command, etc. then it's most likely related to your PATH containing "
characters.
For instance, in Atom editor I was getting the message in the settings view.
"\"GNU was unexpected at this time
This was due to a different program putting in my PATH the following entry
...;C:\"Program Files"\"GNU ARM Embedded;..."
Because of that, the antislash character is read as escaped by some programs, which causes issues because then it's not a pathname delimiter but a simple character.
The solution for me was to remove those "
from the PATH, and everything worked fine.
...;C:\Program Files\GNU ARM Embedded;...
PS: I have a doubt whether or not this can impact the original program (GNU ARM Embedded in this case) that maybe does not support spaces in pathnames. If somebody with more insight can clarify in the comments, I will update my post.
Hope this helps