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-04 05:41
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question about how to use set! View 751 Replies 2
Original Poster Posted 2007-04-19 19:02 ·  中国 河北 廊坊 联通
初级用户
Credits 108
Posts 35
Joined 2007-04-12 15:23
19-year member
UID 84897
Gender Male
From 河北廊坊
Status Offline
Example:
@echo off&setlocal enabledelayedexpansion
set n=abc987
set "m="
set /p=!n:~-6!<nul
set /p=!m:~0,3!<nul
pause

Here  is the backspace character. I'd like to ask, doesn't set /p=!m:~0,3!<nul mean displaying 3 backspace characters, that is, deleting three characters? In this example, shouldn't the final result be abc? But when I run it, the final result is abc98. I just can't figure it out no matter how much I think about it. Why is that?
Floor 2 Posted 2007-04-19 21:33 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Because after this line is output there are still two spaces at the end
set /p=!n:~-6!<nul
Change the above line to
set /p"=!n:~6!!"<nul

I strongly recommend that when you use set in the future, add double quotes whenever possible;
otherwise later on you'll often run into problems with extra spaces or things getting cut off because of spaces;
and you'll often have to waste quite a lot of time looking for this error;
it's best to develop the good habit of adding quotes
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
caucfeiyu +2 2007-04-19 22:50
Floor 3 Posted 2007-04-19 22:50 ·  中国 河北 廊坊 联通
初级用户
Credits 108
Posts 35
Joined 2007-04-12 15:23
19-year member
UID 84897
Gender Male
From 河北廊坊
Status Offline
Solved, thanks, expert! Added points!
Forum Jump: