我正在编写一个批处理脚本,其中我需要在 if
语句中使用通配符来将变量与字符串匹配。如果匹配,程序将走得更远。
if "!_var!"=="str*" (
-- SOME COMMANDS --
)
这是我用过的语法,但我发现它根本行不通。
最佳答案
echo %var% |findstr /b "str" >nul && (
echo yes
some more commands
) || (
echo no
some more commands
)
寻找(/b
=开头的)str
,(不写入屏幕>nul
),如果找到( &&
) 做某事,如果找不到 (||
) 做另一件事。
您还可以添加 /i
使其不区分大小写。
关于windows - 批处理脚本 - 'If Statements' 中的通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23027975/