Background
Let us pull in real quick and talk about a DOS ditch that is easy to get ensnared in.
DOS-Batch
Original
Code
rem display version number ver rem Adding Comments rem https://www.nobody.com/?a=1 IF %ERRORLEVEL% NEQ 0 Echo errorlevel is %ERRORLEVEL%
Output
Output – Image
Output – Text
>specialChars.original.cmd >rem display version number >ver Microsoft Windows [Version 10.0.17763.2686] >rem Adding Comments 1 was unexpected at this time. >rem https://www.nobody.com/?a=1 >
Revision
Outline
- The error is due to the presence of the ? in the rem statement
- We have to escape the question ( ? ) mark
- We escape the question mark by placing the \ ahead of it ( ? )
Code
rem display version number ver rem Adding Comments rem escape the special character ? rem original ? rem revised \? rem https://www.nobody.com/\?a=1 IF %ERRORLEVEL% NEQ 0 Echo errorlevel is %ERRORLEVEL%
Output
Output – Image
Output – Text
>specialChars.revised.cmd >rem display version number >ver Microsoft Windows [Version 10.0.17763.2686] >rem Adding Comments >rem escape the special character ? >rem original ? >rem revised \? >rem https://www.nobody.com/\?a=1 >IF 0 NEQ 0 Echo errorlevel is 0 >
Dedication
Always in dedication to my Bro, Gerald S.
Shared a working cube with him years ago.
That IVY League education goes a long way.
Source Code
GitHub
Gist
DanielAdeniji/dos.batch.remarkStatement.specialChars.original.cmd