Windows批处理文件:多个if条件 [英] Windows batch files: multiple if conditions

查看:764
本文介绍了Windows批处理文件:多个if条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法说类似


如果%1 == 1或1%2 ==

在一个批处理文件?或者,甚至更好,如果我能指定一组候选值的像


如果%1 [1,2,3,4,... 20]


解决方案

的一种方式来实现逻辑或使用多个条件语句的转到相同的标签。

 如果%1 == 1页转到:COND
如果%1 ==页转到:COND
转到:跳过
:条件
someCommand
:跳跃

要测试集合成员,你可以使用一个for循环:

 为%%我在(1 2 3 4 ... 20)如果做1%== %%我someCommand

注意 == 是字符串相等操作。 EQU 是数字相等运算符。

Is there a way to say something like

if %1 == 1 or %1 == 2

in a batch file? Or, even better, if I could specify a set of candidate values like

if %1 in [1, 2, 3, 4, ... 20]

解决方案

One way to implement logical-or is to use multiple conditionals that goto the same label.

if %1 == 1 goto :cond
if %1 == 2 goto :cond
goto :skip
:cond
someCommand
:skip

To test for set membership, you could use a for-loop:

for %%i in (1 2 3 4 ... 20) do if %1 == %%i someCommand

Note that == is the string equality operator. equ is the numeric equality operator.

这篇关于Windows批处理文件:多个if条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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