Linux echo Command Introduction and-N,-e parameter detailed

Source: Internet
Author: User
Tags echo command


The echo command is used to print the value of the shell variable in the shell, or to output the specified string directly. The echo command of Linux, which is very commonly used in shell programming, is often used when printing variable value in a terminal, so it is necessary to understand that the function of the echo command is to display a piece of text on the display, which usually serves as a hint.

Grammar

Echo (options) (parameters) option

-E: Activates the escape character. When the-e option is used, the following characters appear in the string, and are handled in particular, rather than as normal text output:

\a issued a warning sound;
\b Deletes the previous character;
\c finally does not add line symbol;
\f the line but the cursor still stays in the original position;
\n and moves the cursor to the beginning of the line;
The \r cursor moves to the beginning of the line, but does not wrap;
\t Insert tab;
\v and \f are the same;
\\ insert \ Character;
\nnn Inserts the ASCII character represented by the NNN (octal);
Parameters

Variable: Specifies the variable to be printed.

Instance

Print text with color with the echo command:

Text color:

Echo-e "\e[1;31mthis is red text\e[0m"
This is red text \e[1;31m sets the color to red
\e[0m to reset the color back
color code: RESET = 0, black = 30, red = 31, green = 32, yellow = 33, blue = 34, magenta =35, cyan = 36, white =37

Background color:

Echo-e "\e[1;42mgreed background\e[0m"
Greed Background color code: RESET = 0, black = 40, red = 41, green = 42, yellow = 43, blue = 44, magenta =45, cyan = 46, white =47

Text flashing:

Echo-e "\033[37;31;5mmysql Server stop...\033[39;49;0m"
There are other numeric parameters in the red digits: 0 Turn off all properties, 1 set high brightness (bold), 4 underline, 5 flashing, 7 reversed, 8 hidden

Echo-n No Line-wrapping output
$echo-N "123"
$echo "456"

Final output
123456

Instead of
123
456
ECHO-E Processing Special characters

If the following characters appear in the string, they are handled in particular, but not as normal text output:

\a issued a warning sound;
\b Deletes the previous character;
\c finally does not add line symbol;
\f the line but the cursor still stays in the 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 and \f are the same;
\ \ insert \ character;
\NNN inserts the ASCII character represented by the NNN (octal);

The following examples illustrate:

$echo-E "a\bdddd"//front of a will be erased
dddd

$echo-E "a\adddd"/output also emits an alarm sound
Adddd

$echo-E "a\ndddd"/Wrap Line
A
dddd

In the process of using Linux, we often go to download the installation package, download the progress of the time is not more fun, the percentage of download progress is changing, the use of echo-e and-n parameters we can also achieve this effect.

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.