vendredi 12 mars 2021

Windows batch if statement influenced by statements in the if block

When I execute the following Windows batch script on Windows Server 2012:

@echo off
SET v=()
IF 1 == 2 (
  echo hi
  echo %v:~0%
  echo 1 equals 2
) ELSE (
  echo 1 does not equal 2
)


IF 1 == 2 (
  echo %v:0%
  echo 1 equals 2
) ELSE (
  echo 1 does not equal 2
)

I get the following output:

1 equals 2
1 does not equal 2
1 does not equal 2

Can anybody tell me why this happens? I don't want to go into the block starting with echo hi even if the value of v is ().

Aucun commentaire:

Enregistrer un commentaire