Linux echo command details

Source: Internet
Author: User
Tags echo command

Linux echo commands are very common in shell programming and are often used to print the variable value in the terminal. Therefore, it is necessary to understand the echo usage.

The echo command is used to display a piece of text on the monitor, which generally serves as a prompt.
The general format of this command is Echo [-N] string.
Option n indicates that the output text is not followed by a line break. Strings can be enclosed by quotation marks or without quotation marks. When you use the echo command to output a string with quotation marks, the string is output as is. When you use the echo command to output a string without quotation marks, each word in the string is output as a string, each string is separated by a space.

Function Description: displays text.
Syntax: Echo [-ne] [String] or ECHO [-- help] [-- version]
Note: Echo sends the input string to the standard output. The output strings are separated by blank characters, and the line number is added at the end.
Parameter number:-N. Do not wrap the line at the end.
-E if the following characters appear in the string, it will be specially processed and will not be treated as a general
Text output:
 

\ A sends an alert;
\ B Delete the previous character;
\ C does not end with a line break;
\ F line feed, but the cursor remains at the original position;
\ N wrap and move the cursor to the beginning of the line;
\ R move the cursor to the beginning of the line without line breaks;
\ T Insert tab;
\ V is the same as \ F;
\ Insert \ characters;
\ NNN inserts the ASCII characters represented by NNN (octal;
-Help: Display help
-Version: displays version information.

 

 

The echo command is a sub-command of DOS batch processing commands that everyone is familiar with. However, you may not know all of its functions and usage:

1. the switch format that controls whether batchcompute commands display the command line itself during execution: Echo [ON | off] If you want to disable the display of the "echo off" command line itself, add "@" to the front of the command line.

2. display the current echo setting status format: Echo

3. Output prompt information format: the Echo information content is the common usage of the ECHO command. It is also familiar and useful to everyone. However, you should also know the following tips as the doscommand Taojin:

4. Close the DOS command prompt and type echo off at the DOS prompt. You can close the display of the DOS prompt so that only the cursor is left on the screen until you type echo on.

5. empty output line, which is equivalent to entering a carriage return format: Echo. it is worth noting that ". "There must be no space in the middle of the echo, otherwise". "Will be output to the screen as a prompt. In addition, "." can be replaced by any symbol, such as:; "/[/] +. In the following example, the echo. Output carriage return is switched to the input as the time command through the DOS pipeline, which is equivalent to a carriage return after the time command is executed. Therefore, after the current time is displayed, the system automatically returns to the DOS prompt status: C:> echo. | another example of the time ECHO command output empty line is: Echo. add it to the automatic batch processing file so that the prompt screen originally displayed at the bottom of the screen appears at the top of the screen.

6. the format of the answer command: Echo | command file name the above format can be used to simplify some commands that require human-machine interaction (such as: chkdsk/F; format drive:; del *. *). It uses the DOS pipeline command to use the preset reply language output by the echo command as the input of the man-machine conversation command. The following example is equivalent to inputting "Y" press Enter: C:> echo y | chkdsk/f c:> echo y | del A: *. * In the case of a human-machine conversation :*.*

7. create a new file or add the file content format: ECHO file content> file name example: C:> echo @ echo off> autoexec. bat creates an automatic batch file C:> echo C:/cpav/bootsafe> autoexec. bat adds content to the automatic batch processing file C: Type autoexec. bat displays the automatic batch processing file @ echo off C:/cpav/bootsafe

8. Print content to the printer or print control code format: Echo printer control code> PRN echo print content> PRN the example below is to input a print control code to the M-1724 printer. <Alt> 156 press and hold the Alt key and type 156 on the keypad. Similarly, the push is as follows: C:> echo <alt> + 156 <alt> + 42 <alt> + 116> PRN (enter the underline command FS * t) C:> echo <alt >+ 155 @> PRN (enter the initialization command ESC @) C:> echo.> PRN (line feed)

9. Enable the horn to sound C:> echo ^ G "^ G" is input using Ctrl + G or Alt + 007. Multiple ^ g inputs can generate multiple sounds. You can directly add it to a batch file or call it as a batch file.

10. Execute the ESC control sequence to modify the screen and keyboard settings. We know that the DOS Device Driver ANSI. sys provides a set of ESC control sequences used to modify the screen and keyboard settings. If you execute the following batch processing program, you can define the function key F12 as the DOS command "DIR/W" and change the screen color to the blue background of the white character. @ Echo "values [0; 134;" dir/W "; 13 p @ echo" values [1; 37; 44 m (note: in the batch file, the "encoding" character is entered by pressing 27 on the alt keypad in the editing state)

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.