删除传递给批处理文件的参数中的双引号 [英] Remove enclosing double quotes from a parameter passed to a batch file

查看:109
本文介绍了删除传递给批处理文件的参数中的双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在这样调用一个批处理文件:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆