Shell command: The echo command is detailed
Original: https://www.cnblogs.com/xyz0601/archive/2015/04/23/4450736.html
Feature Description : Displays text.
syntax : echo [-ne][string]/echo [--help][--version]
Additional note : Echo will send the input string to standard output. The output strings are separated by white space characters, and a newline number is added at the end.
Parameters :
- n do not wrap in the last line
- e turns on the backslash ESC escape.
If the following character is present in the string, it is handled in particular, not as a general text output:
\a issued a warning sound;
\b Delete the previous character;
\c finally not add the line break symbol;
\f the line but the cursor remains in its 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 is the same as \f;
\ \ insert \ character;
\NNN inserts the ASCII character represented by the NNN (octal);
- e suppress backslash ESC escape (default)
-help Display Help
-version displaying version information
############################################################ #
echo Output Color text The echo command changes the style to output text of different colors and must have the-e option (Turn on Escape in Echo).
The display color of the text terminal can be generated using the ANSI unconventional character sequence.
For example:echo -E "\033[44;37;5m me\033[0m COOL"
Explanation: The "\033[44;37;5m Me" setting background is blue, foreground is white, blinking cursor, output character "ME";
"\033[0m Cool" reset the screen to the default settings, the output character "COOL".
"E" is an optional option for the command echo, which is used to activate the parser for special characters.
"\033" directs an unconventional character sequence (that is, "\033[" means the terminal escape character begins,
"\033" is the ASCII code of the exit key <ESC>).
"M" means to set the property and then end the unconventional character sequence, the real valid characters in this example are "44;37;5" and "0".
modifying "44;37;5" can produce combinations of different colors, which are not related to the sequence of values and encodings.
The encodings you can choose are as follows (these colors are ANSI standard colors): coded colors/actions
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
Some notes : The foreground color of each number is corresponding to the background color minus 10. "M" That ends an unconventional character sequence must follow the preceding number, and cannot have spaces.
Commands can also be written as echo-e "^[[44;37;5m ME \033[0m COOL", where the "^[" is the first to press CTRL-V, and then press <ESC> to generate.
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 '.
#----------------------------------------------------------- #
recommendation : At the front of the shell file, define the output style of the echo command as a variable.
# define ECHO Terminal style
# color:0~6---black, red, green, yellow, blue, purple, cyan, grey
Export echo_style_00= "\033[0m"
# Default Style (black background, white foreground)
Export echo_style_01= "\033[41;33;1m"
# Red background, yellow foregound bold
ECHO-E "${echo_style_01}echo command terminal STYLE example${echo_style_00}"
############################################################ #
Other uses of the echo command
1). The cursor jumps to the 60th column and then displays an OK.
Format: Echo-en ' \033[60g ' && echo OK
Description: "\033[" is the terminal escape character beginning, 60G is the command.
############################################################
Then give a few more powerful script functions 1) cfont #by Zuoyang http://hi.baidu.com/test/
CFont ()
{while (($#!=0))
Do case $ in
-b) Echo-ne ""; ;;
-t) Echo-ne "\ T"; ;;
-N) echo-ne "\ n"; ;;
-black) Echo-ne "\033[30m"; ;;
-red) Echo-ne "\033[31m"; ;;
-green) Echo-ne "\033[32m"; ;;
-yellow) Echo-ne "\033[33m"; ;;
-blue) Echo-ne "\033[34m"; ;;
-purple) Echo-ne "\033[35m"; ;;
-cyan) Echo-ne "\033[36m"; ;;
-white|-gray) Echo-ne "\033[37m"; ;;
-reset) Echo-ne "\033[0m"; ;;
-H|-HELP|--HELP) echo "Usage:cfont-color1 Message1-color2 message2 ...";
echo "eg:cfont-red [-blue message1 message2-red]"; ;;
*) Echo-ne "$";;
Esac
Shift
Done}
The use method is CFont-color string ...
such as: Cfont-cyan ABC
Note that you need to add the-N option when you use the line. You want to restore the default to join the-reset option.
2) Color code table
#!/bin/bash t= ' Gyw '
# The Test text
Echo
echo "Default 40m 41m 42m 43m 44m 45m 46m 47m"
# # FGs for foreground (foreground) color, BG for background (background) color
For FGs in ' m ' 1m ' 30m ' 1;30m ' 31m ' 1;31m ' 32m ' 1;32m ' 33m ' ' 1;33m ' ' 34m ' ' 1;34m ' ' 35m ' ' 1;36m ' 37m ' 1;37m '
Do fg=$ (echo $FGs |tr-d ")
Echo-en "$FGs \033[$FG $T"
For BG in 40m 41m 42m 43m 44m 45m 46m 47m;
Do Echo-en "\033[$FG \033[$BG $T \033[0m"
Done
Echo
Done
Echo
(GO) shell command: echo command detail