What's the best way to declare and use a boolean variable in Batch files? This is what I'm doing now:
set "condition=true"
:: Some code that may change the condition
if %condition% == true (
:: Some work
)
Is there a better, more "formal" way to do this? (e.g. In Bash you can just do if $condition
since true
and false
are commands of their own.)
if defined var
, which gives the benefit of working withinif
,for
, and other parenthetical code blocks without requiring delayed expansion. There's also conditional execution based on zero or non-zero errorlevel. – Fogel%condition%
can be guaranteed to have a value, you don't need them; the quotes are just to avoid a syntax error if it's empty. – Sacramentarianset /A
command just manage 32-bits integers, but that is not exactly the same thing... – Ducky