删除传递给批处理文件的参数中的双引号 [英] Remove enclosing double quotes from a parameter passed to a batch file
问题描述
我正在这样调用一个批处理文件:
I am calling a batch file like this:
test.bat C:\
将C:\
参数传递给批处理文件中的命令,如下所示:
The C:\
parameter is passed to a command within the batch file like this:
start program.bat "%1"
我发现program.bat
正在这样开始:
program.bat "C:\"
是否可以从参数中删除引号,以便program.bat
接收C:\
而不是"C:\"
?
Is it possible to remove the enclosing quotation marks from the parameter so that program.bat
receives C:\
instead of "C:\"
?
推荐答案
%1
照原样计算第一个参数.也就是说,如果参数用引号引起来,则会保留它们.
%1
evaluates to the first parameter as-is. That is, if the parameter is enclosed in quotation marks, they will be preserved.
%~1
在评估之前先去掉引号.
%~1
strips the quotation marks before evaluating.
因此,请在program.bat
中使用%~1
,在该位置需要使用不带引号的第一个参数的值.
So, use %~1
in program.bat
where you need to use the value of the first parameter without quotation marks.
这篇关于删除传递给批处理文件的参数中的双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!