(reprint) The difference between a pipe command and a Xargs (classic explanation)

Source: Internet
Author: User

always do not understand, the pipeline is the result of the previous command as a parameter to the next command, that in | After the addition of Xargs there is no difference

Newuserff wrote:
Lazy snail Gentoo wrote:
The pipeline is to implement "standard input for the previous standard output as a later"
Xargs is a parameter that implements "standard input as a command"

You can try running:

Code:
echo "--help" |cat
echo "--help" |xargs Cat

Look at the difference in the results.


Tried, still not very sure to understand what the meaning of the end, and then explore to see the

If you enter cat directly on the command line without entering anything else, then cat will wait for standard input, so you can

With keyboard input and press ENTER to let cat read the input, CAT returns as is. And if you enter--help, then the cat program will be on the standard output

Print your own Help document. In other words, the pipe character | The arguments passed to the program are not the parameters that you simply enter after the program name, and they are

The read function inside the program such as scanf and get receive, while Xargs is the content as a normal parameter passed to the program, equivalent to your handwriting

Cat--help

From: http://forum.ubuntu.org.cn/viewtopic.php?t=354669

Additional explanations:

There are three files in a directory

A.C B.C C.C

Find. /-print command will print out three filenames

Find. /-print | grep A.C will only print out A.C this file

If you only enter the command grep A.C

Then you only enter the A.C string in the keyboard, A.C will be printed two times, or only the characters you entered

If you are looking for three files, the file includes a Hello character

Find./-print | Xargs grep Hello

Summary: The pipe after the Xargs equivalent to the Xargs after the command return to perform a bit and then input from the keyboard

The result content of the preceding command executed by the pipe character

Plus Xargs is equivalent to directly from the keyboard input pipe character in front of the results of the command execution and then enter

To sum up, the order of carriage return is not quite the same.

(reprint) The difference between a pipe command and a Xargs (classic explanation)

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.