中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-15 12:42
47,812 topics / 349,917 posts / today 0 new / 48,268 members
DOS批处理 & 脚本技术(批处理室) » How to get special characters in batch processing parameters?
Printable Version  1,812 / 5
Floor1 afxwzg Posted 2007-06-05 12:01
初级用户 Posts 9 Credits 24
Little brother, I wrote a batch code that needs to use batch parameters. When testing, I found that some special characters can't be displayed. For example, the following code:
aaa.bat
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal EnableDelayedExpansion
set 111=%1
set 222=%2
set 333=%3
echo !111!
echo !222!
echo !333!
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I entered "aaa.bat !a =a ;a", but only 3 a's were displayed, and the preceding symbols! = ; were not displayed. I added escape characters ^ in front of these characters, but it was still 3 a's. Everyone, how can I get these special symbols?
Floor2 bjsh Posted 2007-06-05 15:50
银牌会员 Posts 621 Credits 2,000
=, ; and several other symbols are treated as separators in parameters;

If you really want to use them as parameters, you can add quotes; and then use %~1 to remove the quotes'

For example, a;ta will be treated as two parameters, a and ta;

! is eaten because variable delay is enabled during set assignment;

You can enable variable delay after the set;

The specific code can be changed to:


aaa.bat "!a" "=a" ";a"


!a
=a
;a
Floor3 afxwzg Posted 2007-06-05 16:31
初级用户 Posts 9 Credits 24
Thanks to the moderator
That is to say, for anything with = and ; characters in the parameters, you need to enclose them in quotes and then remove them in the program
Although this is a bit troublesome, it seems that this is the only way
Floor4 afxwzg Posted 2007-06-05 16:44
初级用户 Posts 9 Credits 24
Also, I want to ask, what is the difference between the delimiter =; and the delimiter space?
Floor5 lxmxn Posted 2007-06-05 21:59
版主 Posts 4,938 Credits 11,386
There should be no difference anymore.
Floor6 rocmagic Posted 2007-10-16 18:37
初级用户 Posts 12 Credits 26
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023