My .cmd file contains:
我的.cmd文件包含:
set /A "@zz+=1"
set @zz
echo:"%%@zz%%"
Produces:
@zz=4
"%@zz%"
The set @zz
shows the variable being properly populated, but echo
acts as though it is not there. Curiously, the commands work fine when run from the command prompt.
集合@zz显示正确填充的变量,但echo表现得好像不存在。奇怪的是,从命令提示符运行时,命令工作正常。
1 个解决方案
#1
3
Actually, batch is doing exactly what it's supposed to. While the normal escape character in batch is ^
, you escape %
in batch scripts like %%
, so you're telling the script to print a literal %
, then the string @zz
, then another literal %
.
实际上,批处理正在完全按照预期进行。虽然批处理中的正常转义字符是^,但您在%%等批处理脚本中转义%,因此您告诉脚本打印文字%,然后是字符串@zz,然后是另一个文字%。
If you really want to echo %4%
, you need three %
signs on each side: echo:"%%%@zz%%%"
如果你真的想要回应%4%,你需要在每一方都有三个百分号:echo:“%%% @ zz %%%”
This tells batch to print a literal %
, then the value of %@zz%
, and then another literal %
.
这告诉批处理打印文字%,然后是%@ zz%的值,然后是另一个文字%。
#1
3
Actually, batch is doing exactly what it's supposed to. While the normal escape character in batch is ^
, you escape %
in batch scripts like %%
, so you're telling the script to print a literal %
, then the string @zz
, then another literal %
.
实际上,批处理正在完全按照预期进行。虽然批处理中的正常转义字符是^,但您在%%等批处理脚本中转义%,因此您告诉脚本打印文字%,然后是字符串@zz,然后是另一个文字%。
If you really want to echo %4%
, you need three %
signs on each side: echo:"%%%@zz%%%"
如果你真的想要回应%4%,你需要在每一方都有三个百分号:echo:“%%% @ zz %%%”
This tells batch to print a literal %
, then the value of %@zz%
, and then another literal %
.
这告诉批处理打印文字%,然后是%@ zz%的值,然后是另一个文字%。