China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-29 19:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to get special characters in batch processing parameters? View 1,665 Replies 5
Original Poster Posted 2007-06-05 12:01 ·  中国 广东 深圳 电信
初级用户
Credits 24
Posts 9
Joined 2007-05-16 17:18
19-year member
UID 88731
Gender Male
Status Offline
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?
Floor 2 Posted 2007-06-05 15:50 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
=, ; 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:

@echo off
set 111=%~1
set 222=%~2
set 333=%~3
setlocal EnableDelayedExpansion
echo !111!
echo !222!
echo !333!


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


!a
=a
;a
Floor 3 Posted 2007-06-05 16:31 ·  中国 广东 深圳 电信
初级用户
Credits 24
Posts 9
Joined 2007-05-16 17:18
19-year member
UID 88731
Gender Male
Status Offline
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
Floor 4 Posted 2007-06-05 16:44 ·  中国 广东 深圳 电信
初级用户
Credits 24
Posts 9
Joined 2007-05-16 17:18
19-year member
UID 88731
Gender Male
Status Offline
Also, I want to ask, what is the difference between the delimiter =; and the delimiter space?
Floor 5 Posted 2007-06-05 21:59 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
There should be no difference anymore.
Floor 6 Posted 2007-10-16 18:37 ·  中国 广东 东莞 电信
初级用户
Credits 26
Posts 12
Joined 2007-10-13 18:43
18-year member
UID 99648
Gender Male
Status Offline
Forum Jump: