我确定您知道%1
,%2
等等.bat内代表传递给命令行上.bat的编号参数。
如果您使用它们作为%~1
,%~2
等,则所有的周围引号将自动删除,如果它们在那里。
考虑这个space-in-args.bat
来进行测试:
@echo off
echo. %1
echo. (original first argument echo'd)
echo.
echo. "%1"
echo. (original first argument with additional surrounding quotes)
echo.
echo. %~1
echo. (use %%~1 instead of %%1 to remove surrounding quotes, should there be)
echo.
echo. "%~1"
echo. (we better use "%%~1" instead of "%%1" in this case:
echo. 1. ensure, that argument is quoted when used inside the batch;
echo. 2. avoid quote doubling should the user have already passed quotes.
echo.
运行:
space-in-args.bat "a b c d e"
输出是:
"a b c d e"
(original first argument echo'd)
""a b c d e""
(original first argument with additional surrounding quotes)
a b c d e
(using %~1 instead of %1 removes surrounding quotes, should there be some)
"a b c d e"
(we better use "%~1" instead of "%1" in this case:
1. ensure, that argument is quoted when used inside the batch;
2. avoid quote doubling should the user have already passed quotes.
参见for /?
(向下滚动接近年底)来找出关于更多这些转换。
你感谢2人,现在,他们已经回答了你的问题?如果是,请接受答案。 – 2013-03-07 01:50:19