Code: Select all
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET "V~1=123"
SET "V~2=456"
SET /A TOT_3=%V~1%+%V~2%
ECHO %V~1%+%V~2% = %TOT_3%
echo pre-missing operator
SET /A TOT~4=%V~1%+%V~2%
echo post-missing operator
ECHO %V~1%+%V~2% = %TOT~4%
GOTO :EOF
The above code produces this result
- C:\Users\Alan>xc
123+456 = 579
pre-missing operator
Missing operator.
post-missing operator
123+456 =
C:\Users\Alan>
That demonstrates that '~' can be used when defining a string variable but not a numerical value.
I am working on something in which it would be convenient to compute a variable "TOT~4"
Do I need to compute variable TOT_4 and then assign its value to a String variable TOT~4
or is there a simple way to escape the evil poison with which '~' has surprised me ?
(I have vague memories of escaping poison with ~~ or ^~ or some such thing)
Regards
Alan