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-08-11 23:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question about character replacement with delayed environment variables View 854 Replies 2
Original Poster Posted 2010-08-15 11:18 ·  中国 广东 深圳 电信
新手上路
Credits 5
Posts 4
Joined 2008-05-14 10:59
18-year member
UID 118636
Gender Male
Status Offline
I recently wrote a script for character replacement with delayed environment variables, as follows:
@echo off
setlocal enabledelayedexpansion
set /p str=字符串:
set /p old=请输入old:
set /p new=请输入new:
set str=!str:!old!=!new!!
echo !str!
pause
But the result I get is oldnew, not the character replacement result I wanted. If I change the percent signs around old and new to exclamation marks, it works. Why? Wasn't it said that under delayed environment variables, variables have to be enclosed in exclamation marks? And the output result is also quite puzzling.
Floor 2 Posted 2010-08-15 13:11 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Variable nesting isn't used like this, refer to:
http://bbs.bathome.net/thread-2899-1-1.html
Floor 3 Posted 2010-08-15 15:21 ·  中国 广东 深圳 电信
新手上路
Credits 5
Posts 4
Joined 2008-05-14 10:59
18-year member
UID 118636
Gender Male
Status Offline
After reading the reference materials, I understand a little. Could the moderator explain how variable nesting is used, and what needs attention when using variable nesting? Thanks.
Forum Jump: