在批处理文件中使用 call 时有没有办法转义 % ?
Is there a way to escape % while using call in batch file?
这是我的第一个批处理脚本。我试图转义 % char 以便不将其用作变量。 Double %% 在使用 start 时有效,但是当我使用 %% 调用它时输入空 space 并且函数缺少参数。
有没有办法在使用 call 时转义 % ?
call wp rewrite structure %%postname%% << FAILED
start wp rewrite structure %%postname%% << OK
我只是想知道为什么 "start" 的同一条语句按预期工作而 "call" 缺少参数。两者都使用额外的 % 字符转义百分号。
你尝试了吗
call wp rewrite structure %%%%postname%%%%
我认为您的 "OK" 行是正确的,因为您需要文字 %postname%
,并且您认识到必须通过在批处理文件中加倍来转义百分比文字。
如果您不将百分比加倍,那么 %postname%
将扩展为环境变量 postname 的值(如果未定义则为空字符串)。
CALL 导致计算两次百分比。第一轮百分比扩展将 %%postname%%
转换为 %postname%
。那就是你想要的。但是随后由CALL发起的第二轮导致%postname%
扩展为变量值
解决方法很简单,再次将百分比加倍:
call wp rewrite structure %%%%postname%%%%
这是我的第一个批处理脚本。我试图转义 % char 以便不将其用作变量。 Double %% 在使用 start 时有效,但是当我使用 %% 调用它时输入空 space 并且函数缺少参数。
有没有办法在使用 call 时转义 % ?
call wp rewrite structure %%postname%% << FAILED
start wp rewrite structure %%postname%% << OK
我只是想知道为什么 "start" 的同一条语句按预期工作而 "call" 缺少参数。两者都使用额外的 % 字符转义百分号。
你尝试了吗
call wp rewrite structure %%%%postname%%%%
我认为您的 "OK" 行是正确的,因为您需要文字 %postname%
,并且您认识到必须通过在批处理文件中加倍来转义百分比文字。
如果您不将百分比加倍,那么 %postname%
将扩展为环境变量 postname 的值(如果未定义则为空字符串)。
CALL 导致计算两次百分比。第一轮百分比扩展将 %%postname%%
转换为 %postname%
。那就是你想要的。但是随后由CALL发起的第二轮导致%postname%
扩展为变量值
解决方法很简单,再次将百分比加倍:
call wp rewrite structure %%%%postname%%%%