Ann*_*ond 0 command-line cmd batch-file
我在批处理文件中有以下代码:
rem capture the date/time(right down to the second) and then assign it to a variable
set yy=%date:~-4%
set dd=%date:~-7,2%
set mm=%date:~-10,2%
set newdate=%dd%%mm%%yy%_%Time:~0,8%
set newdate=%newdate::=%
set foldername=svetlana_backup_%newdate%
set foldername=%foldername: =%
set destination=R:\Backup
if exist %destination% (
rem do stuff if destination exists.
) else (
call:GenerateErrorLog "%destination% not found."
)
:GenerateErrorLog
echo %~1 >> error_log_%foldername%.txt
goto:eof
Run Code Online (Sandbox Code Playgroud)
它生成以下文本文件:
R:\Backup not found.
ECHO is off.
Run Code Online (Sandbox Code Playgroud)
为什么它打印 ECHO is off,如何防止它?
由于该值为%~1空,因此echo报告其状态。
修复方法:使用echo(in place of echo[Space]-(不参与嵌套例程的括号计数,但已发现可以抑制echo空参数 {quirk} 的报告