if 和 else 不强求在同一行上,但是,else 子句必须出现在与 if 后的命令相同的行中,例如:CODE: [Copy to clipboard]
if exist filename (
del filename
) else (
echo filename missing
) 下面的代码不起作用,因为必须通过重起一行终止 del 命令:CODE: [Copy to clipboard]
if exist filename del filename else echo filename missing 以下命令不起作用,因为 else 命令必须在与 if 命令的末尾相同的行上:CODE: [Copy to clipboard]
if exist filename del filename
else echo filename missing 如果要完全在单行上格式化它,可以使用如下形式的原始声明:CODE: [Copy to clipboard]
if exist filename (del filename) else echo filename missing |