The Echo learning notes in Linux

Source: Internet
Author: User
Tags control characters echo command echo display

Let's introduce the standard command line, which contains three parts:

Command_name option argument

Okay, back, echo is sending argument out to standard output (STDOUT), usually to the monitor output.

Or just run down and look at the echo command:

Do you feel strange about a blank line and go back to the shell prompt (just $).

The reason is because ECHO is on a preset, and after argument is displayed, a newline symbol is also sent.

But the command doesn't have any argument, so there's just a newline symbol.

If you feel bad, want to cancel this line symbol, say,-n option can completely help you fix:

This is comfortable, actually echo besides-n option, there are some common options, such as:

-E: Initiate backslash control character conversion

-e: Turn off backslash control character conversion (note different from above)

-N: Cancels newline symbol at end of line (same as C-character function under-e option)

The backslash control characters supported by the Echo command are the following table:

A:alert/bell (ring out from system horn)

B:backspace, which is left? h apart?

C: Remove line break symbol at end of row

E:escape, jump off the key

F:formfeed, changing page characters

N:newline, newline characters

R:return, enter

T:tab, table-hop key

V:vertical tab, vertical table-hop key

N:ascii octal encoding (starting with x 16)

\: Backslash itself

Ok, with these we can print out the commands below to see how powerful echo is:

What's the difference between the top two??? Try to analyze it ...

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

Do you think of the C language of college Tan Haoqiang?

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

Because Ah, behind the E-letter is the H key (b), so the output is no E.

At the end of the hearing a ring, don't worry, that is a masterpiece!

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

If you don't use-N, what's the alternative? ... (Add a C after a).

The echo command is most commonly used in future shell operations and shell script design.

One of the commands.

First a small test, with Echo to check the value of the variable:

...... (this variable, in the future will be told to everyone)

OK, more about the command line format, and the echo command options,

1) echo Display string

An ordinary string can be entered directly into the string after echo, however, when it comes to outputting certain character Furu "There is a problem (this type of writing" is treated as a line operator filtered out, to output a "must play", with the C language printf output requirements like), so it is generally best to use ´string´ or " String "format so that even" can be output easily and intuitively.

#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 The escape display of Echo: plus the-e parameter

Output Multiple lines
#echo-e´hello "Nworld´
Hello
World

Output ASCII character: Echo-e "NNN (NNN is an ASCII character octal code number, does not conform to the octal will be printed in literal sense)
#echo-e´ "61" 62 "101" 141´
1 2 A 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.