Basics of Linux echo command

Source: Internet
Author: User
Tags echo command

echo command

Function: Display characters

Syntax: Echo [-nee][string]

Description: Echo will send the input string to standard output. The output string is separated by a white space character, and a newline number is added at the end

echo "$VAR _name": variable is replaced, double quotation mark table weak reference

Echo ' $VAR _name ': variable does not replace, strong reference

$echo –e "Enter the file name: \c"

Echo needs to print the escape character using the-e parameter.

echo Command options:

-N: Not at the end of the character, line wrapping

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

\a: Warning Sounds

\b: Delete the previous character

\c: Finally, no newline characters are added.

\ n: Wrap and move the cursor to the beginning of the line

\ r: The cursor moves to the beginning of the line but does not wrap
\ t: Insert tab

\ \: Insert \ Character

\0NNN: inserting ASCII characters represented by NNN (octal)

Echo-e "\033[43;31m CentOS Linux \033[0m"

\XHH: Inserts the ASCII represented by the HH (hexadecimal)

echo Output Color text:

The echo command changes the color style to output text of different colors and must have the-e option (to open escape in Echo)

Eg:echo-e "\033[34;43;4;5m say\033[0m HELLO"

\033[34;43;4;5m SAY: Set font color to blue, background color yellow, font underlined and blinking

\033[0m Hello: Reset screen default setting, output character "HELLO"

"E" is an optional option for the command echo, which is used to activate the parser for special characters. "\033" directs the unconventional character sequence (that is, "\033[" means the terminal escape character starts, "\033" is the ASCII code that exits the key <ESC>). "M" means to set the property and then end the unconventional character sequence, the real valid characters in this example are "34;43;4;5" and "0". modifying "34;43;4;5" can produce combinations of different colors and styles, with no relationship between the values and the order of the encodings.

The encodings you can choose are as follows (these colors are ANSI standard colors):

Coded Color/action

0 Reset properties to default settings

1 setting Bold

2 Set half brightness (simulates color of color display)

4 Set underline (simulates color of color display)

5 Setting flashes

7 Setting the 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

Other interesting codes are:

\033[2J Clear the screen

\033[0q Turn off all keyboard LEDs

\033[1q Setting the "SCROLL Lock" indicator (Scroll Lock)

\033[2q Setting the value Lock indicator (Num lock)

\033[3q Setting the CAP Lock indicator (CAPS LOCK)

\033[15:40h move off to line 15th, column 40

\007 beep of the hair bee

Output text with color, the echo command must have the option "-e".

This method can only temporarily change the style of the text of the echo command output and revert to the default after logout. Modify the. bashrc file to modify the default display style. For example: Append a line to the last face of the. bashrc file: Echo-e ' \033[47;30m '.

Exercises: Echo Blink, underline, add color

(7)

(5)

(3)

* (1)

Echo-e "\033[33;42;4;5m*******\033[0m\n \033[31;43;4;5m*****\033[0m\n \033[32;44;4;5m***\033[0m\n \033[34;45;4;5m* \033[0m "

The experimental output phenomena are:

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20160724/1469373354928413.png "title= "1469373354928413.png" alt= "Blob.png" width= "183" height= "118" style= "width:183px;height:118px;"/>


Basics of Linux echo command

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.