dos 批处理文件中通常的转义字符是插入符号,^
. 但是对于百分比,%
变量的分隔符,转义是加倍百分比:%%cd%%
。在循环中使用参数扩展时情况会发生变化。for
它不是像在循环外那样%%~dpnx0
发出%~dpnx0
,而是执行替换,发出D:\Scripts\foo.py
。
这是一个批处理文件演示:
@echo off
echo This is a pipe: ^|
echo Use this var for the current directory: %%cd%%
echo Use this to echo full path of running batch file: %%~dpnx0
for %%a in (foo.py baz.py) do (
echo @python %%~dpnxa ^> %%~na.bat
)
这些是我得到的结果:
This is a pipe: |
Use this var for the current directory: %cd%
Use this to echo full path of running batch file: %~dpnx0
@python d:\Scripts\foo.py > foo.bat
@python d:\Scripts\baz.py > baz.bat
但这就是我想要的:
This is a pipe: |
Use this var for the current directory: %cd%
Use this to echo full path of running batch file: %~dpnx0
@python %~dpnxa > foo.bat
@python %~dpnxa > baz.bat
我尝试过将百分比加倍、三倍和四倍,以及在整个过程中穿插插入符号,但均未成功。