Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
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.

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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.

share|improve this answer
2  
In CMD, echo( may be necessary sometimes - someone has done a test, and echo.%var% may collide with a filename, and so on... –  grawity Jul 13 '11 at 21:04
    
@grawity interesting link, so echo.%var% collides if you have a file called echo in that dir! But how would you do echo %bb% if you had a variable called bb and you didn't want it to display the contents of bb? but just literally %bb%. I see echo.%bb% or echo/%bb% or echo %bb% all have the issue. –  barlop Jul 14 '11 at 13:19
    
@barlop: Try echo ^%bb^% and echo %%bb%%, one of them should work. –  grawity Jul 14 '11 at 13:20
    
@gravvity what about !bb! ? –  barlop Jul 14 '11 at 13:24
    
@barlop echo ^^!bb^! don't know the mechanics of why escaping the first exclamation mark once didn't do it but twice did, but anyway. –  barlop Nov 24 '11 at 11:19

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.

share|improve this answer

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.

share|improve this answer

Just escape the the '/' - so try:

C:\>set g=\/?
share|improve this answer
    
you didn't test that, did you. Try echo %b% after. And anyhow, the escape character in cmd is ^, and notice set g=^/? is the same as set g=/? –  barlop Jul 25 '11 at 19:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.