在 IF 语句中使用 OR WinXP 批处理脚本 [英] Using an OR in an IF statement WinXP Batch Script

查看:18
本文介绍了在 IF 语句中使用 OR WinXP 批处理脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过 IF 语句传递 OR?

Is there a way to pass an OR through an IF statement?

如:

SET var=two
IF "%var%"=="one" OR "two" OR "three" ECHO The number is between zero and four.

推荐答案

没有.

if "%var%"=="one" goto foo
if "%var%"=="two" goto foo
if "%var%"=="three" goto foo
goto afterfoo
:foo
echo The number is between one and three (technically incorrect, since it includes the end points and thus is not between).
:afterfoo

如果您需要更结构化的方法:

If you need a more structured approach:

if "%var%"=="one" set OneToThree=1
if "%var%"=="two" set OneToThree=1
if "%var%"=="three" set OneToThree=1
if defined OneToThree (
    echo Foo
) else (
    rem something
)

这篇关于在 IF 语句中使用 OR WinXP 批处理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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