冷凝If语句批处理文件 [英] Condensing If Statement Batch File

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

问题描述

我有这个批处理脚本有很多if语句。以下是我的几行:

I have this batch script that has numerous "if statements". Here are a couple lines of what I have:

if %c%==PC exit
if %c%==pc exit
if %c%==CMD exit
if %c%==cmd exit
if %c%==MENU exit
if %c%==menu exit
if %c%==KILL exit
if %c%==kill exit

还有更多的可能性,如果有可能的话,真的可以使用一些简化。那么有什么办法可以简化这个吗?也许类似的,如果变量 c 等于其中任何一个退出。或者甚至使if语句不明确这是否可能?实际上,任何简化此操作的方法都很棒,可以大大减少我的批处理脚本的大小。

There are many more possibilities and really could use some simplifying if it is possible. So is there a way I can simplify this? Perhaps something like, if the variable c is equal to any of these exit. Or even make the if statements case insenstitive Is this possible? Really, any way to simplify this would be awesome and could greatly reduce the size of my batch script.

一些附注


  • 此代码已经有效,除了缩小它之外不需要编辑。

  • This code already works and does not need to be edited with the exception of condensing it.

我知道这里有类似的问题,但我不知道如何将它应用到我的问题中。

I know there is a similar question found here, but I do not know how to apply it to my problem.

推荐答案

来自 IF 命令的帮助。 / I开关,如果指定,表示要进行不区分大小写的字符串比较。 / I开关也可用于IF的string1 == string2形式。

if /I %c%==PC exit
if /I %c%==CMD exit
if /I %c%==MENU exit
if /I %c%==KILL exit

这篇关于冷凝If语句批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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