How do you set var=/? in cmd.exe?
C:\>set g=/?
C:\>echo %g%
Displays messages, or turns command-echoing on or off.
ECHO [ON | OFF]
ECHO [message]
Type ECHO without parameters to display the current echo setting.
C:\>
if I do set g="/?" then echo %g% then it includes quotes.
I just want /? without quotes, when I do echo %g% it should just say /?
No greater reason. But it's what I want. Hopefully is possible.
Solution 1:
To get the text to be displayed as output, even if it is the word ON
, the word OFF
, or an option sequence, use the infamous echo dot trick. Instead of the echo
command, use the echo.
command.
C:\>set g=/?
C:\>echo. %G%
/?
C:\>echo. on
on
C:\>echo.%G%
/?
C:\>
Notice the odd behaviour of echo.
with respect to separating whitespace, and with respect to how the command-line parser detects the end of the command name. If you have JP Software's TCC/LE, you can of course still use this rather dubious syntax, which has its roots in the MS-DOS COMMAND
where several punctuation characters in addition to whitespace were "termination" characters, but it's far better to use the more regular native syntax of TCC, not least because it retains ordinary whitespace as the separator between command name and command tail:
[C:\]set g=/?
[C:\]echo ``%G%
/?
[C:\]
TCC's native syntax will not prevent on
and off
from being recognized specially, however. For that you still need the echo.
command.
Solution 2:
Actually it's working as is. :)
When you set "g" to be "/?" and then type echo %g%
you are actually typing echo /?
, which (as it should) gives you the help on echo that you are seeing ("Displays messages, or turns command-echoing on or off...").
If you type echo test%g%
you'll get test/?
returned.
Solution 3:
Actually set g=/?
is correct. The problem is that /? means something special to cmd.exe. It means show help for the command. For example try dir /?
. Or in your case echo /?
.
Run set g
and you will see that g is indeed set to /?
So when you run echo %g%
you are really running echo /?
which tells cmd.exe to print the help message.