Echo of Linux basic commands (which involves bash command reference and replacement)

Source: Internet
Author: User

Echo of Linux basic commands (which involves bash command reference and replacement)

Echo is a common command in Linux. It is essential to use echo flexibly in bash script writing.

In man's manual, display a line of text is displayed as a echo or display a character or number. The explanation seems simple, but this command provides a wide range of functions.

The reason why I wrote the echo content is that a job displays an inverted triangle image composed of any characters and requires that the characters flash and contain the font color and background color.

This job will be put aside and solved later.

First, we will introduce the basic echo information.

The following is the echo command usage information taken from the man manual in the CentOS-6.8.

NAME command NAME
Echo-display a line of text displays a line of text, that is, echo

SYNOPSIS Command Format
Echo [SHORT-OPTION]... [STRING]... echo [SHORT format]... [STRING]...
Echo LONG-OPTION echo LONG format

DESCRIPTION
Echo the STRING (s) to standard output. echo STRING to standard output

-N do not output the trailing newline output without line feed

-E enable interpretation of backslash escapes

-E disable interpretation of backslash escapes (default) disable escape characters

-- Help display this help and exit: displays the exit information with help.

-- Version
Output version information and exit output version information

If-e is in effect, the following sequences are recognized: If-e takes effect, the following transfer characters can be recognized

\ Backslash Escape Character

\ A alert (BEL) Prompt

\ B backspace return character

\ C produce no further output

\ E escape character

\ F form feed

\ N new line break

\ R carriage return

\ T horizontal tab

\ V vertical tab

The above are the echo commands and common usage information.

Here we can see that the most abundant echo commands are-e, which makes the Escape Character take effect. In-e mode, we can enrich the output format of characters, such as flashing characters, background color and font color.

The following is a command of my job to describe the echo function in-e mode.

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

It looks amazing.

Next

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

Make a detailed analysis so that you can have a clearer understanding of it.

Explanation: echo-e has already been clearly introduced. I will not introduce it here. It enables the Escape Character function.

"" For its reason, here we will first explain the references in bash.

Bash references several types

$ () Is a command reference

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

It displays the execution result of the date command.

''Is the same as $ ().

''Weak reference: the input string is displayed.

# Echo 'date'
Date

The date string shown here

"" Strong reference

A single command is often used to make the escape characters in the middle take effect.

$ {} Is a variable reference.

# TEX = tex
# Echo $ {TEX}
Tex

Show variable content

After reading this part, I believe you will have a preliminary understanding of bash command reference and replacement. With this understanding, we should be able to understand why "" quotation marks are used in-e mode. It doesn't matter if you don't know. Just remember it.

"\ 033" guides the sequence of unconventional characters (that is, "\ 033 [" indicates that the terminal escape character starts, "m" indicates that the attribute is set and then the sequence of unconventional characters ends, the actual characters are 45, 32, 5, and 0, and can be changed to 45, 32, or 5. Different color combinations and display formats can be modified. 45; 32; 5. The positions of these numbers can be changed at will.

Encoding color/Action
0. Reset the property to the default setting.
1. Set bold
2. Set half brightness (simulate color display)
4. Set the underline to simulate the color of the color display)
5. Set flashing.
7. Set reverse Images
22. Set the general density
24. Close the underline
25 turn off flashing
27 disable reverse image
30 set the black foreground
31 set the red foreground
32. Set the green foreground
33 set the yellow foreground
34 set the blue foreground
35 set purple foreground
36 set the blue foreground
37 set the White (Gray) Foreground
38. Set the underline on the default foreground color
39. Disable the underline on the default foreground color
40 set a black background
41 set the red background
42 set a green background
43 set a yellow background
44 set the blue background
45 set a purple background
46 set the blue background
47 set a white (Gray) Background
49 set the default black background

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

I used 45 here to set the background color to purple, 32 to set the font color, that is, the foreground color to green, 5 to indicate the flashing mode. 0 m indicates that the character effect ends here.

The first \ 033 [0 m has two spaces, because you do not want to display the side of the small triangle;

The second \ 033 [45; 32; 5 m *** displays three Green and blinking backgrounds in the purple font ***;

The third \ 033 [om \ n is added to \ n because the last * line needs to be wrapped and three spaces need to be added after the line feed;

The fourth \ 033 [45; 32; 5 m * shows a green and blinking purple background *;

The fifth \ 033 [0 m character effect ends here.

Search information:

Linu command reference and replacement

This article permanently updates the link address:

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.