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-06-20 04:46
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » How much do you know about the usage of the echo command? View 8,322 Replies 25
Original Poster Posted 2006-11-27 00:17 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
### Usage of the ECHO Command
The ECHO command is a sub - command of the well - known DOS batch processing commands, but there may be some functions and usages of it that you don't all know. Just take a look:

1. As a switch to control whether the command line itself is displayed when the batch processing command is executed
Format: ECHO
If you want to close the display of the “ECHO OFF” command line itself, you need to add “@” before this command line.

2. Display the current ECHO setting status
Format: ECHO

3. Output a prompt message
Format: ECHO message content

The above are the three common usages of the ECHO command, and they are also what everyone is familiar with and can use. But as a DOS command gold digger, you should also know the following tips:

4. Turn off the DOS command prompt
Typing ECHO OFF at the DOS prompt can turn off the display of the DOS prompt, leaving only the cursor on the screen. The prompt will reappear until you type ECHO ON.

5. Output a blank line, which is equivalent to entering a carriage return
Format: ECHO.
It should be noted that the “.” in the command line should be closely followed by ECHO without a space in between, otherwise the “.” will be output to the screen as a prompt message. In addition, the “.” can be replaced by any one of symbols such as,, : ; " / +.
In the following example, the carriage return output by ECHO. is redirected through the DOS pipe as the input of the TIME command, which is equivalent to giving a carriage return after the TIME command is executed. So when it is executed, the system will automatically return to the DOS prompt state after displaying the current time:
C:>ECHO.|TIME
Another application example of the ECHO command outputting a blank line is: adding ECHO. in the auto - batch file to make the originally displayed prompt screen at the bottom of the screen appear at the top of the screen.

6. Answer the question in the command
Format: ECHO answer|command file name
The above format can be used to simplify the operation of some commands that need human - computer dialogue (such as: CHKDSK / F; FORMAT Drive:; del *.*). It is to use the DOS pipe command to take the preset answer output by the ECHO command as the input of the human - computer dialogue command. The following example is equivalent to entering “Y” and a carriage return when the called command has a human - computer dialogue:
C:>ECHO Y|CHKDSK/F
C:>ECHO Y|DEL A :*.*

7. Create a new file or add content to a file
Format: ECHO file content> file name
ECHO file content>> file name
For example: C:>ECHO @ECHO OFF>AUTOEXEC.BAT to create an auto - batch file
C:>ECHO C:\CPAV\BOOTSAFE>>AUTOEXEC.BAT to append content to the auto - batch file
C:TYPE AUTOEXEC.BAT to display the auto - batch file
@ECHO OFF
C:\CPAV\BOOTSAFE

8. Output print content or print control codes to the printer
Format: ECHO printer control code> PRN
ECHO print content> PRN
The following example is to input print control codes to the M - 1724 printer. <Alt> 156 is to hold down the Alt key and type 156 on the numeric keypad. The same situation is类推:
C:>ECHO +156+42+116>PRN (input the underline command FS*t)
C:>ECHO +155@>PRN (input the initialization command ESC@)
C:>ECHO.>PRN (new line)

9. Make the speaker beep
C:>ECHO ^G
“^G” is input by Ctrl + G or Alt + 007. Entering multiple ^G can produce multiple beeps. The usage is to directly add it to the batch file or call it as a batch file.

10. Execute ESC control sequences to modify screen and keyboard settings
We know that the device driver ANSI.SYS of DOS provides a set of ESC control sequences for modifying screen and keyboard settings. For example, executing a batch program with the following content can define the function key F12 as the DOS command “DIR / W” and modify the screen color to white characters on a blue background.
@ECHO”←





Floor 2 Posted 2006-11-27 01:00 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Haha, it's a pity to tell you that Wengier has collected no less than you.

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 3 Posted 2006-11-27 01:02 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
It seems that the last two items are only effective in command or ANSI.SYS. Don't believe it? Try it for yourself~~

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 4 Posted 2006-11-27 01:15 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
ECHO ^G is also effective in cmd,

@ECHO”←[0;134;”DIR/W”;13p
@ECHO”←[1;37;44m requires loading ansi.sys to be effective. Does ansi.sys work in Windows, and how to load it?
Floor 5 Posted 2006-11-27 20:56 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Saw a few new ones, thank you the楼主.
Floor 6 Posted 2006-11-29 02:11 ·  中国 江苏 连云港 电信
中级用户
★★
传说中的菜鸟
Credits 275
Posts 112
Joined 2005-04-22 00:00
21-year member
UID 38486
Gender Male
Status Offline
This command is very little discussed in the book. At first, I felt it had weak functions, but it turns out there are so many subtleties!
Floor 7 Posted 2007-01-12 10:22 ·  中国 江苏 连云港 联通
高级用户
★★★
前进者
Credits 641
Posts 303
Joined 2007-01-10 02:57
19-year member
UID 76009
Gender Male
Status Offline
Got it's learned. I don't know how to use the last two items.
Floor 8 Posted 2007-01-14 16:10 ·  中国 上海 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
Correct it: use the escape function of ANSI.SYS without the " symbol
Floor 9 Posted 2007-02-03 10:50 ·  中国 广东 深圳 宝安区 电信
初级用户
Credits 67
Posts 32
Joined 2007-01-16 01:40
19-year member
UID 76621
Gender Male
Status Offline
Learning batch processing, your materials are really eye-opening
Floor 10 Posted 2007-02-13 23:12 ·  中国 上海 联通
初级用户
★★
Credits 148
Posts 69
Joined 2006-11-23 23:04
19-year member
UID 71504
Gender Male
Status Offline
echo is here, wahaha...

Anyway, I've never been able to make the speaker on my case make a sound. I've basically tried all the methods mentioned on the forum! The others are all commonly used!
Floor 11 Posted 2007-03-12 07:58 ·  中国 江苏 南京 电信
初级用户
Credits 76
Posts 39
Joined 2007-03-09 06:54
19-year member
UID 81169
Gender Male
Status Offline
Supporting the first floor......I've seen it........too shocking.....................
狐狸喜欢狡猾。。
Floor 12 Posted 2007-03-12 10:02 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 493
Posts 228
Joined 2007-02-16 00:38
19-year member
UID 79596
Gender Male
From 安徽
Status Offline
Floor 13 Posted 2007-03-21 11:32 ·  中国 江苏 苏州 电信
中级用户
★★
我是DOS学者
Credits 367
Posts 180
Joined 2006-05-14 10:53
20-year member
UID 55507
Gender Male
From 重庆
Status Offline
Originally posted by tianzizhi at 01:15:
ECHO ^G is also effective in cmd,

@ECHO”←



This I also tested in CMD, so much fun, heh heh~~~~ I can't believe it's the beep sound.
Floor 14 Posted 2007-03-23 14:19 ·  中国 江苏 南京 电信
新手上路
Credits 9
Posts 5
Joined 2007-03-23 12:12
19-year member
UID 82667
Gender Male
Status Offline
Good stuff
Floor 15 Posted 2007-04-15 10:29 ·  中国 广西 南宁 电信
初级用户
Credits 30
Posts 15
Joined 2007-04-15 06:31
19-year member
UID 85230
Gender Male
Status Offline
I only understand the first 3 usages of this command, and I just found out about the later ones after reading. Thanks.
Forum Jump: