我已经阅读了大部分有关此内容的主题,并了解复杂的if/then块在Windows命令行中是一个痛苦,所以我尝试缩减,我仍然最终得到"(此时此刻意外)错误.
我觉得它与确定%确认%的位置有关,但我真的不确定.最初我在块中有一个goto,我读到的是禁止的,所以我尝试使用嵌套的if/if/else来解决这个问题.没有骰子.
我不能想到比我正在做的更基本的东西,因为命令shell的内部工作方式超出了我的范围.
第一版:
@echo off
TITLE cleanup
:: make user confirm they want to cleanup old epub conversion files
set /p confirm = "Are you sure? (y/n): "
if %confirm% == y (
rm ePub
rm IP
rm OP
md IP
exit
) else (
if %confirm% == n (
exit
) else (
set /p confirm = "Are you sure? (y/n): "
)
)
Run Code Online (Sandbox Code Playgroud)
目前的缩小版本:
@echo off
TITLE cleanup
:: make user confirm they want to cleanup old epub conversion files
set /p confirm = "Are you sure? (y/n): "
if %confirm% == y (
rm ePub
rm IP
rm OP
md IP
exit
) else (
exit
)
Run Code Online (Sandbox Code Playgroud)
当变量实际为空时,您的代码已经破坏了语法.尝试
if "%confirm%" == "y" (
Run Code Online (Sandbox Code Playgroud)
这保证了在左侧总有一些东西==.