The Linux output of printf explains the difference between---> and echo

Source: Internet
Author: User
Tags float double

Printf

Have you ever been in touch with printf? If you learn C language you must be familiar with, if not, do not hurry, I guarantee you will soon!

Let's take a look at the case:

    

As you can see, the echo output will wrap the text, but the printf command will not wrap, and you may want to change the line oh, what would you do??

     

That's it, are you going to feel the trouble?? Echo is more simple, isn't it? Don't rush to see the big trick:

Let's say I have a line of text like this:

    

All of a sudden, you feel like it. When the output is wrapped for each field, you use the Echo output as follows:

    

Does it feel stupid? It's not going to work, it has to be e-

Okay, then printf shows up, huh:

    

Do you think it is very useful?? , you might think that it's just one less-e, and that's looking at one:

    

What did you see??

Not bad??

You may be a little bit of text, but you have to think about it. If I want to output 10000 lines, how do you echo output? printf requires only the symbols defined on the previous%s street.

    

Working mode is like this, each time it will call this format, OK, and you want to say what printf is doing;

Formatted text. You may have thought that%s could be replaced by something else?

Yes, you can also switch to%F.

  

Wait a series of classes, formatted text, not the fame of the waves

%s string

%f floating-point format (float double)

%cascii character that displays the first character corresponding to

%d%i decimal Number

%o Octal with no plus or minus

%u decimal

%x Hex

Percent per se

Don't worry, there are escape characters.

\a warning character is usually an ASCII-coded Bel character

\b Back

\c

\f Page Change

\ nthe line break

\ r Enter

\ t tab

\v Vertical Tab

\ \ Itself

\DDD octal number from one to three

  

Wait, I'm talking about a

  

Explain

  

Suddenly thought:

  

Obsessive Compulsive disorder look underneath

  

You can do anything for the output, isn't it?

Okay, it's over.

Is it going to happen?

This printf can be used in awk.

The Linux output of printf explains the difference between---> and echo

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.