Batch file 使用带转义序列的调用^
我必须通过CALL语句执行一个批处理文件,并向该文件传递一个参数。在我需要使用^标志之前,一切正常 我正在运行XP,这个问题可以通过两个简单的命令重现: 不请自来Batch file 使用带转义序列的调用^,batch-file,Batch File,我必须通过CALL语句执行一个批处理文件,并向该文件传递一个参数。在我需要使用^标志之前,一切正常 我正在运行XP,这个问题可以通过两个简单的命令重现: 不请自来 c:\>echo password: "secret(<^>)secret" password: "secret(<^>)secret" c:\>回显密码:“secret()secret” 密码:“secret()secret” 随叫随到 c:\>call echo password: "sec
c:\>echo password: "secret(<^>)secret"
password: "secret(<^>)secret"
c:\>回显密码:“secret()secret”
密码:“secret()secret”
随叫随到
c:\>call echo password: "secret(<^>)secret"
password: "secret(<^^>)secret"
调用回显密码:“secret()secret”
密码:“secret()secret”
如何避免在使用CALL时不复制^sign?这样您就无法避免它,因为
CALL
总是在第二次重新解析该行之前将所有插入符号加倍
如果确实需要使用调用
,则应将数据放入变量中,并在调用插入符号后展开
set "myVar=secret(<^>)secret"
set myVar
call echo Password "%%myVar%%"
设置“myVar=secret()secret”
设置myVar
调用回显密码“%%myVar%%”
但是即使这样,如果您的秘密包含引号,或者如果您尝试使用不带引号的变量,您也会遇到问题
因此,您最好在此处使用延迟扩展。这也将在括号内工作(无需调用)
setlocal EnableDelayedExpansion
(
set "myVar=secret(<^>)secret"
echo !myVar!
)
setlocal EnableDelayedExpansion
(
设置“myVar=secret()secret”
回音!玛瓦!
)
如果您对双插入符号的来源感兴趣,您可以阅读您需要使用
call
来回显密码吗?我想您需要调用,因为您在括号中,但是延迟扩展是更好的选择