Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? fetch the current escape character and store it to a variable

Jul
532
10
Maybe there’s an automatic variable for this, but I coudln’t find it.

obviously we’d have to turn command escaping off with setdos first, but:

Is there a way to store the current escape character?

That way... it can be changed and then reverted.
 
Rather than saving it in a variable, I would suggest changing it inside a SETLOCAL / ENDLOCAL block.

Though, in truth, I can't remember the last time I felt the need to change the escape character. The command separator, yeah, occasionally. But the escape character?
 
Maybe there’s an automatic variable for this, but I coudln’t find it.

obviously we’d have to turn command escaping off with setdos first, but:

Is there a way to store the current escape character?

That way... it can be changed and then reverted
Code:
v:\> set ESCAPE_CHAR=%@word["=",1,%@execstr[setdos | findstr ESCAPE]]

v:\> echo The escape char is %escape_char
The escape char is ^
 
Code:
C:\>set esc=%@option[escapechar]

C:\>set esc
^

C:\>

... But I still think SETLOCAL / ENDLOCAL is the better way. Working with the current escape character is always going to be clumsy, because... it's the current escape character!
 
Probably more useful:
Code:
C:\>set esc=%@ascii[%=%=]

C:\>set esc
94

C:\>

The resulting value contains no special characters and can be plugged directly into setdos /e. No fuss, no muss, no oily residue.
 
Agreed that working with its ASCII value will be a lot easier.
 
Yea, my escape char is the +/ symbol, and my command separator is the caret. Been this way since the 1990s and in about 4000 bat files and not gonna change.

And also, recently, in these forums, I was given a @ReReplace[] that ONLY works if i change the escape character before running it. (the "matching non-quotes" one) ... So if that script were to be able to run on someone else’s machine, i would need to store their escape char and change it to mine, then change it back aftewards out of politeness.

Code:
C:\>set esc=%@option[escapechar]

C:\>set esc
^

C:\>

... But I still think SETLOCAL / ENDLOCAL is the better way. Working with the current escape character is always going to be clumsy, because... it's the current escape character!

I’ve actually never used setlocal/endlocal and feel like i’m really missing out on something.

So wait, if you change your escape char/command separator inside a setlocal block, it only affects that block?!?!?!

Problem is, a lot of my stuff leaves environment variables set for auditing values.. how do you poke those OUT of the setlocal?
 
Ahh i see endlocal accepts a list of variables you want to export.

Dang. Wish I’d been using that the last 25 years.
 
Thanks for all the help!!
 
Back
Top