Linux echo command

This command is used to print the value of the shell in the shell variable, or directly output the specified string. linux echo command, very commonly used in shell programming, print variable value at the time the terminal is often used, it is necessary to understand the function usage under the echo of the echo command is to display a text on the display, a general play prompts.

grammar

echo (option) (parameters)

Options

-e: activate the escape character.

Use -eoption, if the character appears in the string, then be treated specially, will not it as normal text output:

  • \ A warning sound;
  • \ B before deleting a character;
  • \ C Finally, do not add line breaks;
  • \ F new line but the cursor still remain in the original position;
  • \ N wrap and move the cursor to the first line;
  • \ R cursor to the beginning of the line, but do not wrap;
  • \ T Insert Tab;
  • \ V and \ f the same;
  • \\ inserted into the \ character;
  • \ Nnn insert nnn (octal) ASCII character represented;

parameter

Variable: Specifies the variable you want to print.

Examples

Print text with color with the echo command:

Letter color

echo -e "\e[1;31mThis is red text\e[0m"
This is red text
  • \e[1;31m Set the color to red
  • \e[0m The color set back again

Color code: Reset = 0, 30 = black, red = 31, green = 32, 33 = yellow, blue = 34, 35 = magenta, cyan = 36, 37 = white

Background color

echo -e "\e[1;42mGreed Background\e[0m"
Greed Background

Color code: Reset = 0, 40 = black, red = 41, green = 42, 43 = yellow, blue = 44, 45 = magenta, cyan = 46, 47 = white

Flashing text

echo -e "\033[37;31;5mMySQL Server Stop...\033[39;49;0m"

There are other numerical parameters of the red numbers: 0 Close all attributes, a set of high brightness (in bold), underline 4, 5 flashes, reverse display 7, 8 blanking

Reprinted from  https://man.linuxde.net/echo  have changed.

Guess you like

Origin www.cnblogs.com/frankzdcx/p/12500864.html