2

I had just showed a friend of mine some of the cool stuff you can do with the command prompt and batch code and she gotten really interested and wants to try it out on her own when she has the time. Shortly after that, I had gotten the idea of making a nice, well polished batch file that will not only demonstrate, but also display display the code in the code on the command window with out the command window executing the commands.

Example: the code in question, %date%, will display the current date when I have the code of echo %date% on the line. I would like to have %date% to be displayed like normal text.

What code am I missing to have %date% and %time% and any other batch code be displayed as normal text so the person having fun with the file can see the code without having to cipher through the code to find the code I am wanting them to learn?

P.S.

I have a feeling this question might have been answer through a different thread and if so, fee free to link me to it. Thank you!

  • 7
    You need to escape percent symbols with percent symbols. `echo %%date%%`. – Squashman Dec 23 '19 at 18:57
  • 2
    just because you will probably need it soon: the escape character for most other "poison characters" (chars that have a special meaning in `cmd`) is a caret `^`: `echo ^&^<^>^|` – Stephan Dec 23 '19 at 19:35
  • 1
    For the sake of completeness: in command prompt the `%`-escaping by doubling does not work, so you need to do `echo %^date%` to literally return `%date%` (given that no variable `%^date%` is defined)... – aschipfl Dec 23 '19 at 19:58
  • 1
    _The underlying question however, is why would somebody want to learn code from somebody, who themselves don't know how to code the code they're trying to teach?_ – Compo Dec 23 '19 at 20:36
  • 2
    Delete the first line `echo off`. –  Dec 23 '19 at 22:39
  • @Compo: discovering something together is a fun way to learn - and not necessarily an ineffective one. (That's one of our reasons to be on SO, isn't it?) – Stephan Dec 24 '19 at 09:24
  • @Mark: Command repetition shows the command *after* expanding variables, so it won't print `echo %date%`, but something like `echo 24.12.2019` (depending on the local settings) – Stephan Dec 24 '19 at 09:26
  • @Compo: it's "teaching" vs. "exploring together". You are absolutely right about the first one. – Stephan Dec 24 '19 at 09:30

0 Answers0