“rem” comment in .bat file causes error “25 was unexpected at this time”

后端 未结 2 1231
梦如初夏
梦如初夏 2021-01-13 15:26

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
相关标签:
2条回答
  • 2021-01-13 15:49

    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]
    
    0 讨论(0)
  • 2021-01-13 15:56

    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.

    0 讨论(0)
提交回复
热议问题