Dos batch - basic if / else does not work

I have:

@echo off
echo before
IF 1 == 1 (
    echo got it
) ELSE (
    echo missed
}
echo done

This code just prints "earlier" and nothing else. I have no idea what I'm missing ...

+5
source share
2 answers

You have the wrong type of bracket at the end of your ELSE - you have }instead ). Change it to:

@echo off
echo before
IF 1 == 1 (
    echo got it
) ELSE (
    echo missed
)
echo done

conclusion:

before
got it
done
+14
source

it works as if in a nested style

IF %CHUSEL%==0 (
  SET IP=10.148.24.1
) ELSE (
  IF %CHUSEL%==1 (
      SET IP=10.148.24.2
  ) ELSE (
      IF %CHUSEL%==2 (
          SET IP=10.148.24.3
      ) ELSE (
          IF %CHUSEL%==3 (
             SET IP=10.148.24.4
          )
      )
   )
)
0
source

All Articles