What happens to the IF command when I connect to it?

Here is my script:

   @echo off
    echo.|if defined 1 geq 1 echo 1 is geq than 1
    echo.|if defined 2 gtr 100 echo 2 is gtr than 100

    echo.|if 1 gtr gtr 100 echo 1 is gteater than 100
    echo.|if 100 lss gtr 100 echo 100 is gteater and the same time less than 100

conclusion:

1 is geq than 1
2 is gtr than 100
1 is gteater than 100
100 is gteater and the same time less than 100

What happens to the team IF?

+2
source share
2 answers

The party parser combines the first tokens after IF.

To get an idea, you can use a variable cmdcmdline.

From batch file

@echo off
echo pipe | if defined 1 geq 1 echo %%cmdcmdline%%

At the output, you can see that definedu are 1combined, so this is the reason for the strange results

C: \ Windows \ system32 \ cmd.exe / S / D / c "if defined1 geq 1 echo% CMDCMDLINE%"

, %%cmdcmdline%% %^cmdcmdline%, cmd- .

+2

:

if defined 1 geq 1 echo 1 is geq than 1

:

if defined 1 if 1 geq 1 echo 1 is geq than 1
+2

All Articles