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-13 03:03
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » [Help] A question about using Echo in a batch file to create a file and write text? View 1,878 Replies 7
Original Poster Posted 2003-07-31 00:00 ·  中国 广东 肇庆 电信
高级用户
★★
Credits 578
Posts 135
Joined 2003-07-10 00:00
23-year member
UID 6709
Gender Male
Status Offline
In a batch file, I want to create a test.bat under D:\, with the content: set aaa=bbb

So:
................
echo set aaa= >d:\test.bat
echo bbb >>d:\test.bat

But after executing the above statements, the content of d:\test.bat turns out to be:
set aaa=
bbb
instead of:
set aaa=bbb

How can I make the strings output by the above two command lines go to the same line in d:\test.bat?
Floor 2 Posted 2003-08-01 00:00 ·  中国 广东 广州 黄埔区 电信
初级用户
★★★
Credits 1,480
Posts 377
Joined 2003-06-06 00:00
23-year member
UID 3875
Gender Male
Status Offline
Actually, you already know how to do it yourself....
Wouldn't echo set aaa=bbb>d:\test.bat do it
欢迎大家访问我的主页!
精品.爱好http://iso.533.net
Floor 3 Posted 2003-08-01 00:00 ·  中国 广东 肇庆 电信
高级用户
★★
Credits 578
Posts 135
Joined 2003-07-10 00:00
23-year member
UID 6709
Gender Male
Status Offline
The above example was just an analogy!
What I want to know is: how can I make the content output twice with the ECHO command be printed onto the same line in test.bat!
Floor 4 Posted 2003-08-02 00:00 ·  中国 福建 福州 电信
初级用户
Credits 183
Posts 29
Joined 2003-06-22 00:00
23-year member
UID 5695
Gender Male
Status Offline
That kind of idea won't work, ECHO absolutely outputs with a line break!
Floor 5 Posted 2003-08-02 00:00 ·  中国 安徽 滁州 天长市 电信
银牌会员
★★★
Credits 1,835
Posts 648
Joined 2002-11-08 00:00
23-year member
UID 197
Gender Male
Status Offline
The ECHO command under DOS is too weak, not satisfying at all
Floor 6 Posted 2003-08-02 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
The following is quoted from LanE's post at 2003-8-2 10:54:28:
The ECHO command under DOS is too weak, not satisfying at all


Then GNUish DOS commands (such as PRINTF, etc.) are also pretty good..
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 7 Posted 2003-09-29 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re hzy:

There are three ways of thinking about making them output on the same line:

1. Find a way not to output the carriage return:
echo definitely won't work for this. You can try the GNUish commands the moderator mentioned; I personally use oecho.exe. If you can't find any of those, just write one yourself directly in C or assembly, it's simple anyway. Also, debug can write it too. If none of those methods suit your taste, then you can try the following idea.

2. Just use echo to output, then find a way to delete the carriage return:
This is rather tricky. So far I've only seen using debug to reduce the file length by two bytes and then save it again, but this requires knowing the length of the source file in advance, so its use is somewhat limited. In addition, some editing software that supports pipe operations (such as edlin under dos5) or binary string replacement software (such as hexc in the undisk package) can also do this.
echo r cx >delfeed.scr
echo source file length minus 2, then convert it to hexadecimal >> delfeed.scr
echo n sample2.tx>>delfeed.scr
echo s >> delfeed.scr
debug sample1.txt < delfeed.scr

hexc sample1.txt sample2.txt 0d0a ""

3. Directly prepare the needed file in advance instead of outputting it temporarily. This method is suitable when the content of sample1.txt is fixed; using an editor to pre-edit the required header file without a carriage return is not very difficult.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 8 Posted 2003-10-01 00:00 ·  中国 福建 漳州 广电网
中级用户
SHOCI@@
Credits 228
Posts 41
Joined 2003-10-01 00:00
22-year member
UID 10566
Gender Male
Status Offline
The following is quoted from willsort's post at 2003-9-29 3:20:20:
Re&nbsp;hzy:

&nbsp;&nbsp;&nbsp;&nbsp;There are three ways of thinking about making them output on the same line:

&nbsp;&nbsp;&nbsp;&nbsp;1. Find a way not to output the carriage return:
&nbsp;&nbsp;&nbsp;&nbsp;echo definitely won't work for this. You can try the GNUish commands the moderator mentioned; I personally use oecho.exe. If you can't find any of those, just write one yourself directly in C or assembly, it's simple anyway. Also, debug can write it too. If none of those methods suit your taste, then you can try the following idea.

&nbsp;&nbsp;&nbsp;&nbsp;2. Just use echo to output, then find a way to delete the carriage return:
&nbsp;&nbsp;&nbsp;&nbsp;This is rather tricky. So far I've only seen using debug to reduce the file length by two bytes and then save it again, but this requires knowing the length of the source file in advance, so its use is somewhat limited. In addition, some editing software that supports pipe operations (such as edlin under dos5) or binary string replacement software (such as hexc in the undisk package) can also do this.
&nbsp;&nbsp;&nbsp;echo&nbsp;r&nbsp;cx&nbsp;>delfeed.scr
&nbsp;&nbsp;&nbsp;echo&nbsp;source file length minus 2, then convert it to hexadecimal&nbsp;>>&nbsp;delfeed.scr
&nbsp;&nbsp;&nbsp;echo&nbsp;n&nbsp;sample2.tx>>delfeed.scr
&nbsp;&nbsp;&nbsp;echo&nbsp;s&nbsp;>>&nbsp;delfeed.scr
&nbsp;&nbsp;&nbsp;debug&nbsp;sample1.txt&nbsp;<&nbsp;delfeed.scr

&nbsp;&nbsp;&nbsp;hexc&nbsp;sample1.txt&nbsp;sample2.txt&nbsp;0d0a&nbsp;&quot;&quot;

&nbsp;&nbsp;&nbsp;&nbsp;3. Directly prepare the needed file in advance instead of outputting it temporarily. This method is suitable when the content of sample1.txt is fixed; using an editor to pre-edit the required header file without a carriage return is not very difficult.



Still can't understand it
≡≡☆⌒_⌒☆≡■◆■≡☆⌒_⌒☆≡≡    
(の)゛在﹍這個...ロ丗界里ヤ
(の) ╱︶ 誰對o..﹎οО誰錯┈?
 ìòvè ╭☆
╭~~~★ ╭ ︶╮
╱︶(o'.'o)︶╲ ╱︶(-'.'-)︶╲
Forum Jump: