在批处理文件中使用调用时,是否可以逃脱%? [英] Is there a way to escape % while using call in batch file?

查看:59
本文介绍了在批处理文件中使用调用时,是否可以逃脱%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一个批处理脚本.我试图转义%char,以便不将其用作变量.使用start时,双精度%%可以工作,但是当我使用%%进行调用时,请输入空格和缺少函数的参数.

This is my first batch script. I was trying to escape % char so that is not used as variable. Double %% works when using start, but when I use %% with call it input en empty space and function missing parameter.

在使用通话时是否可以逃脱%?

call wp rewrite structure %%postname%% << FAILED
start wp rewrite structure %%postname%% << OK

我只是想知道为什么带有开始"的相同语句能按预期工作,而呼叫"却缺少参数.两者都使用附加的%char来转义百分号.

I was just wondering why is that same statement with "start" worked as expected and "call" was missing an argument. Both were escaping percent sign using additional % char.

推荐答案

我认为您的确定"行是正确的,因为您希望使用文字%postname%,并且您知道百分比文字必须为通过在批处理文件中加倍来逃脱.

I presume your "OK" line is OK because you want the literal %postname%, and you recognize that percent literals must be escaped by doubling within a batch file.

如果未将百分比加倍,则将%postname%扩展为环境变量postname的值(如果未定义,则为空字符串).

If you don't double the percents, then %postname% is expanded to the value of environment variable postname (or empty string if not defined).

CALL导致对百分比进行两次评估.第一轮百分比扩展将 %% postname %% 转换为%postname%.那就是你想要的.但是,随后由CALL启动的第二轮操作将%postname%扩展为变量值.

CALL causes percents to be evaluated twice. The first round of percent expansion converts %%postname%% into %postname%. That is what you want. But then the second round initiated by CALL causes %postname% to be expanded to the variable value.

解决方案很简单,第二次将百分比翻倍:

The solution is simple, double the percents a second time:

call wp rewrite structure %%%%postname%%%%

这篇关于在批处理文件中使用调用时,是否可以逃脱%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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