标题: [文本处理] 批处理如何原样输出百分号(变量不扩展) [打印本页]
作者: hothbo 时间: 2018-2-23 16:04 标题: 批处理如何原样输出百分号(变量不扩展)
本帖最后由 pcl_test 于 2018-3-28 05:36 编辑
请教一个很小白的问题- echo netsh i i show in>>temp.bat
- echo ^@set /p idx=请输入“本地连接”的Idx编号:>>temp.bat
- echo netsh interface ipv4 set dns name=^%idx^% static 192.168.1.230 >>temp.bat
- echo netsh interface ipv4 add dns name=^%idx^% 192.168.1.223 index=2 >>temp.bat
- echo ping 127.1 -n 3 >null>>temp.bat
复制代码
运行后的结果是:
netsh i i show in
@set /p idx=请输入“本地连接”的Idx编号:
netsh interface ipv4 set dns name= static 192.168.1.230
netsh interface ipv4 add dns name= 192.168.1.223 index=2
ping 127.1 -n 3
可是我需要的运行结果是:
netsh i i show in
@set /p idx=请输入“本地连接”的Idx编号:
netsh interface ipv4 set dns name=%idx% static 192.168.1.230
netsh interface ipv4 add dns name=%idx% 192.168.1.223 index=2
ping 127.1 -n 3
我单独把第三和第四句在dos下运行,运行结果是我需要的结果。可是为什么组合到一起却不是我想得到的结果?
作者: ivor 时间: 2018-2-23 17:09
☛☛☛☛
作者: hothbo 时间: 2018-2-23 17:25
回复 2# ivor
谢谢!!按照您说的运行结果达到预期效果了!
只是能否说明一下为什么要这样改么?
作者: ivor 时间: 2018-2-23 17:37
Escape Characters- Escape Characters
- Character to be escaped Escape Sequence Remark
- % %% May not always be required in doublequoted strings, just try
- ^ ^^ May not always be required in doublequoted strings, but it won't hurt
- & ^&
- < ^<
- > ^>
- | ^|
- ' ^' Required only in the FOR /F "subject" (i.e. between the parenthesis), unless backq is used
- ` ^` Required only in the FOR /F "subject" (i.e. between the parenthesis), if backq is used
- , ^, Required only in the FOR /F "subject" (i.e. between the parenthesis), even in doublequoted strings
- ; ^;
- = ^=
- ( ^(
- ) ^)
- ! ^^! Required only when delayed variable expansion is active
- " "" Required only inside the search pattern of FIND
- \ \\ Required only inside the regex pattern of FINDSTR
- [ \[
- ] \]
- " \"
- . \.
- * \*
- ? \?
复制代码
作者: hothbo 时间: 2018-2-23 17:40
回复 4# ivor
万分感谢!!!收藏之!
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |