Batchfile:声明和使用布尔变量的最佳方法是什么? [英] Batchfile: What's the best way to declare and use a boolean variable?

查看:209
本文介绍了Batchfile:声明和使用布尔变量的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在批处理文件中声明和使用布尔变量的最佳方法是什么?这就是我现在正在做的事情:

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
)

是否有更好,更正式"的方式来做到这一点?(例如,在Bash中,如果$ condition 可以执行,因为 true false 是它们自己的命令.)

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.)

推荐答案

我暂时坚持最初的回答:

I'm sticking with my original answer for the time being:

set "condition=true"

:: Some code...

if "%condition%" == "true" (
    %= Do something... =%
)

如果有人知道更好的方法,请回答此问题,我们很乐意接受您的回答.

If anyone knows of a better way to do this, please answer this question and I'll gladly accept your answer.

这篇关于Batchfile:声明和使用布尔变量的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆