Simple echo command usage and instance, echo command instance
In CentOS 6.8, the flexible use of options and parameters is displayed in the form of instances, which gives you a concise understanding of echo usage.
I. Syntax: echo [SHORT-OPTION]… [STRING]… ; Echo [Option]… [Parameters]
Purpose: output the required content to the terminal or other files.
Ii. Usage of instances and option parameters:
(1) Direct text output
Echo 'Welcome To cnblg'
(2) output variable value: Suppose a variable is defined, bl = "Welcome To CNBLGS"
Echo $ bl
Explanation: bl is the defined variable name, followed by a value assignment, and the string must be enclosed. $ Follow the variable name directly.
(3) The difference between double quotation marks after echo:
Explanation: the single quotation marks after echo indicate strong references. The single quotation marks indicate what is output, while the double quotation marks indicate weak references. The variable value will replace the variable name output.
(4) Add-e to the options. escape characters are available:
\ T: Insert a tab, that is, hop display
Echo-e "Hello Linux \ tHello World"
The comparison without-e is as follows:
Echo "Hello Linux \ tHello World"
Also, escape characters are as follows:
\ A sends an alert;
\ B Delete the previous character;
\ C does not end with a line break;
\ N wrap and move the cursor to the beginning of the line;
\ R move the cursor to the beginning of the line without line breaks;
\ V is the same as \ f;
\ Insert \ characters;
\ 0nn Insert the ASCII value represented by 0nn (octal;
(5) output the command prompt in color. The result is displayed as follows:
Command: echo-e "\ e [1; 32 mHello Linux \ e [0 m"
Among them, \ e [1; 32 m is the part of the overall escape, the number represents the color of the font and the color of the background, and so on. In this example, the Number 1 indicates the font brightness (BOLD), 32 indicates that the font is green, and 0 indicates that all properties are disabled.
(6) echo outputs to a file instead of a terminal.
Explanation: At the beginning, the test1 file does not exist. The echo output is redirected to the test1 file. The cat command is used to view the file content.