The echo of the Linux Base command (involving bash command references and replacement parts)

Source: Internet
Author: User
Tags echo command


Echo is a more common command in Linux, especially in bash scripting, which is essential for its flexible use.


In the man manual, the explanation is: Display a line of text, translation comes back or more popular point is to show characters or numbers. The explanation looks simple, but the command can be implemented with a lot of functionality.

The reason I write about Echo is because of a job where the content of the job is to display an inverted triangle of any character, requiring the character to blink and have a font color followed by the background color.

This assignment is set aside and resolved later.


Let's introduce the basic information of ECHO.

below is from centos-6.8 in . man The echo command captured in the manual uses information.

name    command name        echo - display a line  of text    display a line of text, that is, echo synopsis    command use format         echo [short-option]... [string]...  echo [Short format] ... [String]...       echo long-option                     echo  Long Format description      Command Description        echo the string (s)  to  standard output.  echo string to standard output        -n      do not output the trailing newline    No line break after output         -e     enable interpretation of  backslash escapes  make the escape character effective    &Nbsp;   -e     disable interpretation of backslash  escapes  (default)   Disable escape characters        --help display  this help and exit   Show use Help to exit information        --version                          version                output version information and exit   Output Version Information                  if -e is in effect , the following sequences are recognized:  IF-e is in effect, the following transfer characters can be identified         \\     backslash    Backslash escape Character                \a     alert  (BEL)   Prompt         \b     backspace   BACKSPACE         \c     produce no further output         \e     escape  Escape Character         \f     form feed       \n      new line   line Break        \r      carriage return         \t      horizontal tab  Horizontal Tab        \v      vertical tab   Vertical Tab

The above is the command of ECHO and commonly used information.

It can be seen here that the most abundant command of ECHO is that-e causes the escape character to take effect. In-e mode we can enrich the output of the characters, such as to let the characters blink, with background color and font color.

Below I show a command of my homework to detail the echo function in-e mode.

Echo-e "\033[0m \033[45;32;5m***\033[0m\n \033[45;32;5m*\033[0m"

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/84/97/wKioL1eVskyiTBwIAAAktYOywxI174.gif "title=" 01.gif "alt=" Wkiol1evskyitbwiaaaktyoywxi174.gif "/>

It looks pretty flashy.

Here's the

Echo-e "\033[0m \033[45;32;5m***\033[0m\n \033[45;32;5m*\033[0m"

Detailed analysis so that we can have a clearer understanding of it

explain : Echo-e in front of a very clear introduction, here is not more introduction. Its role is to turn on the escape character function

"Because of its sake here first explain the references in bash


Bash contains a few points of reference

$ () is a command reference

# echo $ (date) Monday, July 25, 2016 14:37:12 CST

It shows the execution result information for the date command.

"Is the same as $ ()

' weak reference : Enter something to display the input string

#echo ' Date ' date

The date shown here is the string

"" Strong reference

Used in a single command to make the middle escape character effective.

${} is a variable reference

#TEX =tex# Echo ${tex}tex

Display variable Contents


This part of the content after reading I believe you have a preliminary understanding of bash command references and substitutions, with these knowledge, we should be able to understand why in-e mode using the "" quotation. I don't know, it's okay, just remember.


"\033" directs the unconventional character sequence (that is, "\033[" means that the terminal escape character begins, "M" implies setting the property and then ends the unconventional character sequence, where the actual characters are 45;32;5 and 0, and the modified 45;32;5 can modify different color combinations and display forms. 45;32;5 These digital positions can be arbitrarily changed.

coded color/action
           0           Reset Properties to default settings
           1           set Bold
           2           set half brightness (color of analog color display)
          4           Set underline (simulates color of color display)
          5            Set blinking
          7            Set Reverse image
22 Setting general Density
24 Turn underline off
25 Flashing off
27 Turn off reverse image
30 setting Black foreground
31 set Red foreground
32 Setting Green foreground
33 Setting Yellow foreground
34 Set Blue Foreground
35 Setting Purple foreground
36 Setting the Cyan foreground
37 Setting White (gray) foreground
38 underline on the default foreground color
39 Turn the underline off on the default foreground color
          40 Setting a black background
41 Setting the red background
42 Setting the green background
43 Setting the yellow background
44 Setting the blue background
45 Setting purple Background
46 Setting the Cyan background
47 Set White (gray) background
49 Setting the default black background

Echo-e "\033[0m \033[45;32;5m***\033[0m\n \033[45;32;5m*\033[0m"

I used 45 here to set its background color to purple, 32 to set the font color that is, the foreground color is green, and 5 indicates the blinking mode. the 0m represents the end of the character effect.

After the first \033[0m there are two spaces, because do not want to let the small triangle display;

The second \033[45;32;5m*** shows a purple font of three * * * with a green and flashing background;

The third \033[om\n the reason is because the last * to change the line, after the line will be followed by three of spaces;

The fourth \033[45;32;5m* display background is a purple font for a green and flashing a *;

The end of the fifth \033[0m character effect.




Find the information:

http://blog.csdn.net/qualcent/article/details/7106483 echo Usage information

http://www.linuxidc.com/Linux/2015-05/117259.htm linu Command Reference and substitution

Manual of Man in CentOS6.8

This article is from "Zhang Fan-it's fantasy drifting" blog, please be sure to keep this source http://chawan.blog.51cto.com/9179874/1829672

The echo of the Linux Base command (involving bash command references and replacement parts)

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.