如果语法Windows批处理 [英] If syntax in windows batch
本文介绍了如果语法Windows批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在Windows批处理文件这项工作:
I'm trying to make this work in a windows batch file:
if not exist "%~n1.ext" (
set /P z="PROMPT (y,n)?"
if /i "%z%" == "y" (
echo if is working
)
)
但无论输入是什么,它永远不会进入回声一部分。这是一个错误的语法?
But no matter what the input is, it never goes into the echo part. Is there something wrong in the syntax?
推荐答案
当你使用一个块中的变量之间((
和)
,则需要启用延迟扩展:
When you use a variable inside a block (between (
and )
, you need to enable delayed expansion:
setlocal enabledelayedexpansion
set var=hello
if "a"=="a" (
set var=world
echo %var% !var!
)
这篇关于如果语法Windows批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文