I know this is going to be a confusing year, because my first post of this year is on a topic I don't really understand.
For some time now I have been confused what the correct method to escape certain characters from being interpreted when I try to print them out. Let's say I want to print this line:
< & >
I can't just say
echo < & >
Because I'll get an error that way (try it yourself if you don't believe me). I have to escape those special characters. To do that I can use the caret (^).
echo ^< ^& ^>
Nice and easy. But then if I want to print this line:
The batch interpreter does something really baffling. If I'm doing it from command line, I can escape it with a caret like other special characters.
But it I do it from inside a batch file, that no longer works. I have to escape the % not with a caret, but with another %.
Confuse the hell out of me, I tell you. So now I live by these rules:
- Always escape special characters using a caret in front of the special character.
- Except when you are in a batch file and need to escape a %, then use a %%.
I hope that helps some of you. Oh wait, nobody reads this blog but me. Oh, well.