Simple echo command usage and instance, echo command instance

Source: Internet
Author: User

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.

  

 

     

 

 

 

 

  

    

    

Related Article

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.