Re: Bug in CMD.exe? Parentheses confused



Rich Pasco wrote:

However, using such an assignment inside a block leads to
confusion, e.g.

if 1==1 (
set /a result = 2*(3+4)
)

which leads to an "Unbalanced parenthesis" error as the
closing parenthesis on the arithmetic expression is
mistaken as the closing parenthesis on the conditional
block.

It's not out of place to escape all suspect on the right of the "set something=" statement. E.g., this would work:

~~
@echo off
if 1==1 (
set /a result = 2*^(3+4^)
)
echo result=%result%
~~

And this one too:

~~
@echo off
if 1==1 (
set /a result =^ ^2^*^(^3^+^4^)
)
echo result=%result%
~~

.


Loading