4

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.

js2010
  • 13,551
  • 2
  • 28
  • 40
  • 1
    not quite weird. rem has parameters, well one which is `/?` – Gerhard Aug 19 '20 at 17:27
  • @Gerhard yes, I just narrowed it down. I had a web address as a comment and it really threw me off. – js2010 Aug 19 '20 at 17:28
  • ah, yes, I see the edit. So I will link you to something to show you how cmd interprets a script. – Gerhard Aug 19 '20 at 17:28
  • Here is a [link](https://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts) which should help you understand, I could have explained, but why should I if it was already done :) – Gerhard Aug 19 '20 at 17:31
  • @Gerhard Thanks. I put the original web link back in, to show how confusing it can be. – js2010 Aug 19 '20 at 17:32
  • 1
    Yes, so one way to eliminate it, seeing as it is a `rem`ark is to double quote it. `rem "https://sourceforge.net/p/jedit/bugs/4084/?limit=25"` – Gerhard Aug 19 '20 at 17:33

2 Answers2

5

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.

aschipfl
  • 28,946
  • 10
  • 45
  • 77
0

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]
js2010
  • 13,551
  • 2
  • 28
  • 40
  • Putting it into doublequotes when it isn't a `rem`ark is standard practice anyhow. Try it without the `rem`, and use a URL which includes other potentially problematic characters, like `&` for instance, then doublequote the URL and see the difference. – Compo Aug 19 '20 at 19:15
  • @Compo & doesn't seem to do anything, at least in windows 10 1909 – js2010 Aug 19 '20 at 19:27
  • As you've clearly not embraced my previous comment in the manner I intended it, what happens when you use this specific string in the same way, _(when not a remark)_, e.g. `start https://swisscows.com/web?query=Ben & Jerry's`. Do you see an error message due to the ampersand, and do you get a browser results page for `Ben` or `Ben & Jerry's`. Now as your string is only text for reading there is absolutely no reason why you could not doublequote it, it isn't going to confuse any reader in that format, `rem "https://sourceforge.net/p/jedit/bugs/4084/?limit="`. – Compo Aug 20 '20 at 17:26
  • @compo My bad, I thought you meant in an rem statement. – js2010 Aug 21 '20 at 00:59