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-07-01 22:52
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Can one echo output multiple lines? View 3,491 Replies 18
Original Poster Posted 2007-11-26 10:36 ·  中国 江西 吉安 遂川县 电信
中级用户
★★
Credits 253
Posts 112
Joined 2006-05-31 11:12
20-year member
UID 56308
Gender Male
Status Offline
echo (1&2&3)>test.txt
Floor 2 Posted 2007-11-26 11:13 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
The following code is saved as echo2.cmd
@echo off
:start_echo
set start_echo=%1
if not defined start_echo goto end
echo %1
shift
goto start_echo
:end


When executing
echo2 abc def ghi
or echo2 abc def ghi>test.txt
第一高手 第二高手

Floor 3 Posted 2007-11-26 11:27 ·  中国 江西 吉安 遂川县 电信
中级用户
★★
Credits 253
Posts 112
Joined 2006-05-31 11:12
20-year member
UID 56308
Gender Male
Status Offline
Thanks to the enthusiasm of the person above, but unfortunately it's not the result I wanted~

This can also be achieved
@echo off
set /p input=
for %%a in (%input%) do echo %%a>>test.txt

I just want to ask if echo has such a function, a single command to output multiple lines
Also: It's rare to see the application of shift...

[ Last edited by junyee on 2007-11-26 at 11:28 AM ]
Floor 4 Posted 2007-11-26 11:35 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
No reliance on echo2.cmd, there's no other way except for
echo2.cmd is more convenient to use than yours
echo2 line 1 content (space) line 2 content (space) line 3 content.....
第一高手 第二高手

Floor 5 Posted 2007-11-26 12:19 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
E:\Cmd>type xecho.bat
@echo this is the first line for echo^

this is the second line^

the end
E:\Cmd>xecho.bat
this is the first line for echo
this is the second line
the end

E:\Cmd>
Recent Ratings for This Post ( 5 in total) Click for details
RaterScoreTime
everest79 +15 2007-11-26 20:50
junyee +1 2007-12-01 19:04
429499381 +4 2008-01-16 16:35
huahua0919 +4 2008-01-16 17:14
plp626 +4 2008-02-03 10:20
Floor 6 Posted 2007-11-26 18:58 ·  中国 广西 钦州 电信
新手上路
Credits 6
Posts 3
Joined 2007-09-28 02:05
18-year member
UID 98446
Gender Male
Status Offline
Wow, the person upstairs is really good!
It turns out that adding a ^ at the end of the line and then leaving a blank line below works.
I tried it and it's pretty good.
Floor 7 Posted 2007-11-27 01:23 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Can moderator lxmxn explain the principle?
Floor 8 Posted 2007-11-27 01:46 ·  中国 北京 中国科学院研究生院玉泉四公寓
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
^When it first appears, it means to escape the following character
Floor 9 Posted 2007-12-22 20:57 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Does the next line also count as subsequent characters?
Floor 10 Posted 2007-12-23 02:34 ·  中国 新疆 石河子 电信
初级用户
Credits 50
Posts 25
Joined 2007-03-29 14:07
19-year member
UID 83301
Gender Male
Status Offline
The moderator is indeed powerful
Floor 11 Posted 2008-01-15 13:11 ·  中国 山东 烟台 联通
中级用户
★★
Credits 257
Posts 123
Joined 2008-01-05 11:08
18-year member
UID 107722
Gender Male
From 烟台
Status Offline
Learning
路 是自己选的
学习 是为了具备解决问题的能力
Floor 12 Posted 2008-01-15 18:54 ·  中国 广东 梅州 电信
中级用户
★★
Credits 262
Posts 129
Joined 2007-07-11 06:50
18-year member
UID 93679
Gender Male
Status Offline
Moderator, if there are multiple lines and spaces are needed in the middle, how to do it?
Floor 13 Posted 2008-01-16 17:07 ·  中国 黑龙江 大庆 大庆中基石油通信建设有限公司
高级用户
★★
Credits 547
Posts 261
Joined 2006-04-15 16:50
20-year member
UID 53887
Status Offline
echo2 123 456 789
Not implemented
123
456
789
Display effect!
Floor 14 Posted 2008-01-18 01:22 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by kidzgy at 2008-1-15 18:54:
Moderator, if there are multiple lines and spaces are needed in the middle, what should be done?

B:\PERL>type xecho.bat
@echo one^

^

^

the end^
goodbye
B:\PERL>xecho.bat
one


the end goodbye

B:\PERL>
Floor 15 Posted 2008-01-18 09:29 ·  中国 山西 吕梁 联通
新手上路
Credits 7
Posts 4
Joined 2007-07-28 10:43
18-year member
UID 94176
Gender Male
Status Offline
Forum Jump: