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-08 01:40
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How can the echo command in DOS be made to not automatically append a newline when outputting? View 1,759 Replies 4
Original Poster Posted 2007-10-25 14:15 ·  中国 河南 濮阳 联通
新手上路
Credits 16
Posts 5
Joined 2007-06-04 19:41
19-year member
UID 90252
Gender Male
Status Offline
To generate a file a.txt with the content "123456" using the for /l command, you can modify the command as follows:

```batch
@echo off
setlocal enabledelayedexpansion
set "str="
for /l %%d in (1,1,6) do (
set "str=!str!%%d"
)
echo !str!>a.txt
endlocal
```

This code first initializes an empty string, then appends each number from 1 to 6 to the string within the loop. Finally, it echoes the concatenated string to the file a.txt, thus avoiding the line breaks.
Floor 2 Posted 2008-04-07 22:56 ·  中国 福建 福州 鼓楼区 电信
新手上路
Credits 4
Posts 2
Joined 2008-03-20 10:19
18-year member
UID 113457
Gender Male
Status Offline
setlocal enabledelayedexpansion
set str=

for /l %%d in (1,1,6) do set str=!str!%%d
echo !str!
pause
Floor 3 Posted 2008-04-07 23:32 ·  中国 北京 顺义区 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
```
for /l %a in (1,1,6) do @<nul,set/p=%a
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
oilio +2 2008-04-11 19:37
我今后在论坛的目标就是做个超级坏人!!!
Floor 4 Posted 2008-04-07 23:35 ·  中国 北京 华为云
银牌会员
★★★
Credits 1,436
Posts 739
Joined 2007-10-11 17:44
18-year member
UID 99469
Gender Male
Status Offline
95 is quite not bad, o(∩_∩)o... Haha
Floor 5 Posted 2008-04-10 21:41 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,284
Posts 538
Joined 2002-11-02 00:00
23-year member
UID 129
Gender Male
Status Offline
Forum Jump: