Linux echo learning notes

Source: Internet
Author: User
Tags echo command echo display

This article introduces how to use echo in linux. echo is a very simple and direct LINUX Command.

First, we will introduce the standard command line, which contains three parts:

Command_name option argument

Okay. Back, echo is to send argument to STDOUT, usually to the display output.

Run the echo command directly:

 

Is it strange that a blank line is used to return to shell prompt (that is, $.

The reason is that, on the preset echo, after the argument is displayed, a line break symbol is also sent.

However, the command above does not have any argument, so there is only one line break.

If you feel uncomfortable, you can cancel the line feed.-n option can help you solve the problem:

 

This is quite comfortable. In fact, besides the-n option, echo also has some common options, such:

-E: Start the conversion of backslash control characters.

-E: Turn off the backslash to control character conversion (note the difference above)

-N: cancel the line break at the end of the line (same as the c character function under the-e Option)

The following table lists the backslash control characters supported by the echo command:

A: ALERT/BELL (send ringtones from system speakers)

B: BACKSPACE, that is, left? Division h?

C: cancel the line break at the end of the line.

E: ESCAPE, skip key

F: FORMFEED

N: NEWLINE, line feed character

R: RETURN, enter key

T: TAB, table hop key

V: vertical tab, VERTICAL table hop key

N: ASCII octal encoding (x-based hexadecimal format)

\: Backslash itself

OK. With these commands, We can output the following command to see how powerful echo is:

 

 

What are the differences between the two above ??? Try to analyze it ......

..............................

Do you think of Tan haoqiang's C language?

..................................

Because, what is behind e? H Division key (B), so no e is output.

When I hear a ring at the end, don't worry. It's a's masterpiece!

Because the-n option is used at the same time, shell prompt is followed by the second line.

If you don't need-n, what else can you do ?.......... (Add c after ).

In the future shell operations and shell script design, the echo command is the most commonly used

Command.

First try the cool and use echo to check the variable value:

...... (This variable will be mentioned later)

OK. For more information about the command line format and echo command Options,

1) echo display string

A normal string can be input directly after echo, but this will cause problems when some characters are output, such as "(in this way," It is filtered out as a row operator, to output a "must be typed", similar to the requirements of C language printf output), it is generally better to use 'string' or "string" format, so that even "can be output, convenient and intuitive.

# Echo hello world
Hello world

# Echo hello "world
Hello world

# Echo hello "" world
Hello "world

# Echo 'Hello "" world "Or: echo" hello "" world"
Hello "" world

2) echo escape display: add the-e Parameter

Output multiple rows
# Echo-e 'Hello "nworld'
Hello
World

Output ascii character: echo-e "NNN (NNN is the octal code number of the ascii character. If it does not conform to octal, it will be printed literally)
# Echo-e '"61" 62 "101" 141'
1 2 A

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.