我確定您知道%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