By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!Or put it on one line.Current workaround is to wrap IF into another subshell, btw.
v:\> type iftest.btm
@ECHO OFF
ECHO "Test line" | IF "%1" == "-d" (FIND /I "line") ELSE (ECHO "Fail!")
v:\> iftest.btm
"Fail!"
v:\> iftest.btm -d
"Test line"
TCC-RT 22.00.40 x64 Windows 7 [Version 6.1.7601]
STC:
Code:@ECHO OFF ECHO "Test line" | IF "%1" == "-d" ( FIND /I "line" ) ELSE ( ECHO "Fail!" )
CMD runs as expected, TCC breaks with "5/6: Unbalanced parentheses ("/"6: Unknown command )".
@ECHO OFF
ECHO "Test line" | ( IF "%1" == "-d" (
FIND /I "line"
) ELSE (
ECHO "Fail!"
)
)
To clarify, CMD creates a subshell with (), much like POSIX shell do.
Constructions like
Are equally valid in CMD and POSIX.Code:( echo 1 echo 2 echo 3 ) > file.ext
If it would have been smarter, it'd recognize entire IF as a block operator without "wrapping it into a single line, like CMD does".
That would've been smart.