问题
Isn't this weird? Do .bat rem commands have some kind of escape code?
file.bat:
rem https://sourceforge.net/p/jedit/bugs/4084/?limit=25
Running it:
C:\Users\admin>file.bat
25 was unexpected at this time.
C:\Users\admin>https://sourceforge.net/p/jedit/bugs/4084/?limit=25
I don't see any errorlevel.
回答1:
The rem command supports one argument, namely /?, and it is greedy for it. Your URL contains that string.
The = is a standard token separator (just like SPACE, TAB, ,, ;), and so the remainder seems to be interpreted as another (invalid) command.
Putting the remark text in between quotation marks helps here since /? is no longer detected:
rem "https://sourceforge.net/p/jedit/bugs/4084/?limit=25"
When you write this:
rem/ https://sourceforge.net/p/jedit/bugs/4084/?limit=25
the /? portion is no longer detected too. However, special characters like &, <, >, |, ( and ) are then recognised.
Another alternative is to use a ::-style comment, which is actually an invalid label (labels begin with a :, see goto /? and call /?):
:: https://sourceforge.net/p/jedit/bugs/4084/?limit=25
Special characters are not a problem here, but this must not be used within a parenthesised block of code.
回答2:
Oh, that's weird. Rem is like a regular command that answers to /? for help, even if the /? is buried somewhere in another string. I'm told that putting the address in doublequotes fixes it.
C:\Users\admin>rem /?
Records comments (remarks) in a batch file or CONFIG.SYS.
REM [comment]
Or this whole string without the 25 gives the same result:
rem https://sourceforge.net/p/jedit/bugs/4084/?limit=
Records comments (remarks) in a batch file or CONFIG.SYS.
REM [comment]
来源:https://stackoverflow.com/questions/63491984/rem-comment-in-bat-file-causes-error-25-was-unexpected-at-this-time