An explanation of ECHO commands in Linux

Source: Internet
Author: User
Tags echo command echo message

The echo command for Linux, which is very common in shell programming, is often used when printing variable value under a terminal, so it is necessary to understand the use of Echo

The function of the echo command is to display a piece of text on the display, which generally acts as a hint.
The general format of the command is: Echo [-n] String
where option n means that the output text is not wrapped, the string can be quoted, or it can be unquoted. When you output a quoted string with the Echo command, the string is output as it is, and when you output an unquoted string with the echo command, each word in the string is output as a string, separated by a space between the strings.

Feature Description: Displays text.
Syntax: Echo [-ne][string] or echo [--help][--version]
Additional note: Echo will send the input string to standard output. The output strings are separated by white space characters, and a newline number is added at the end.
Parameter:-n do not wrap in the last line
-E If the following characters appear in the string, they are handled in particular, not as a general
Text output:
\a issued a warning sound;
\b Delete the previous character;
\c finally not add the line break symbol;
\f the line but the cursor remains in its original position;
\ n Wraps and the cursor moves to the beginning of the line;
\ r The cursor moves to the beginning of the line, but does not wrap;
\ t Insert tab;
\v is the same as \f;
\ \ insert \ character;
\NNN inserts the ASCII character represented by the NNN (octal);
Help Display Help
–version displaying version information

The echo command is a sub-command of a DOS batch command that everyone is familiar with, but some of its features and usage maybe you don't all know, don't believe you see:

1. As the switch format for controlling whether the batch command displays the command line itself at execution time: ECHO [on| OFF] If you want to turn off the display of the ECHO off command line itself, you need to precede the command line with "@".

2. Show current echo Settings status format: Echo

3. Output hint Message format: Echo message content The above is the three common uses of the echo command, which is familiar to you and will be used, but as a DOS command you should also know the following tips:

4. Close the DOS command prompt, type echo off at the DOS prompt, to turn off the display of the DOS prompt so that the screen leaves only the cursor until you type echo on, and the prompt will appear again.

5. Output a blank line, which is equivalent to entering a carriage return format: ECHO. It is worth noting that in the command line ". "You can't have spaces immediately after echo, otherwise." "will be used as a prompt to output to the screen. In addition ". "Can be used,:;"/[/]+ any symbol instead. In the example below, Echo. The output carriage return, which is switched by a DOS pipeline as input to the time command, is equivalent to giving a carriage return after the time command executes. Therefore, the system will automatically return to the DOS prompt state after the current time is displayed: c:〉echo.| Another example of an application where the time echo command outputs a blank line is: Echo. Add in the automatic batch file, so that the original display at the bottom of the screen, appear on the screen.

6. Question format in reply command: Echo Reply | command file name the above format can be used to simplify some of the commands that require man-machine dialogue (for example: Chkdsk/f;format drive:;del * *) operation, It is the input to the man-machine Dialogue command by a DOS pipeline command to output the echo command in the preset reply. The following example is equivalent to entering a "Y" carriage return when a conversation occurs in the command that is invoked: C:〉echo y| chkdsk/f C:〉echo y| DEL A:*. *

7. Create a new file or add a file content format: Echo file contents > filename Echo file contents > > filename For example: C:〉echo @ECHO off〉autoexec. BAT establishes an automatic batch file C:〉echo c:/cpav/bootsafe〉〉autoexec. BAT appends content C:type AUTOEXEC to the automatic batch file. BAT displays the automatic batch file @ECHO OFF C:/cpav/bootsafe

8. Output print or print control code format to the printer: Echo Printer control code >prn echo Print content >prn The following example is to enter the print control code to the M-1724 printer.  156 is the ALT key to type 156 on the keypad, and so on: c:〉echo〈alt〉+156〈alt〉+42〈alt〉+116〉prn (Enter the underline command Fs*t) c:〉echo〈alt〉[email PROTECTED]〉PRN (Input initialization command [email protected]) C:〉ECHO.〉PRN (newline)

9. Make the Horn sound c:〉echo ^g "^g" is a ctrl+g or alt+007 input, multiple ^g can generate multiple beeps. This is done by adding it directly to a batch file or making a batch file call.

10. Perform ESC control sequence modify screen and keyboard settings We know that the DOS device driver Ansi.sys provides a set of ESC control sequences to modify the screen and keyboard settings. A batch program that performs the following can define the function key F12 as the DOS command "dir/w" and change the screen color to a white character blue background. @ECHO "←[0;134;" Dir/w "; 13p @ECHO" ←[1;37;44m (note: The input method for the "←" character in a batch file is to press ALT 27 on the keyboard in the edit state)

echo Command writes content to a file

1. Overlay style (the original content in the file is overwritten)

echo ' www.baidu.com ' > Local/seed.txt

echo AAAAA > Seed.txt

2. Add style (new content is added after the original content)

echo "www.baidu.com" >> local/seed.txt

Echo aaaaa >> seed.txt

An explanation of ECHO commands in Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.