Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am little bit confused by the following syntax. Although it works, It do not understand why it works. It seems, like there are two pipes attached to the diff command. But isn't there only one STDIN?

Examples:

diff <(echo "foobar") <(echo "barbaz")
diff <(cat foo.txt) <(cat bar.txt)
share|improve this question

migrated from stackoverflow.com Feb 14 '12 at 15:56

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 11 down vote accepted

The pipes are simply bound to different file descriptors than 0 (stdin):

$ echo <(true)
/dev/fd/63
$ echo <(true) <(true)
/dev/fd/63 /dev/fd/62

A process can of course have more than one open file descriptor at a time, so there's no problem.

share|improve this answer
    
If I only had known its called temporary pipes, I would have been able to google it. Thank you! –  iblue Feb 8 '12 at 14:24
    
@iblue: I don't think it's called "temporary pipes". It's just pipes, as created by the pipe() system call. –  Sven Marnach Feb 8 '12 at 14:26
    
To be very exact, it might be called "anonymous named pipes", but it is sufficient to google it. –  iblue Feb 8 '12 at 14:29
    
The process is not started with any additional file descriptors open. Instead, it is passed the name of a named pipe or some file in /dev/fd. –  William Pursell Feb 8 '12 at 19:50
    
@WilliamPursell: As the above examples demonstrate, at least on my Linux box the latter approach is taken. But "files" in /dev/fd are just place holders for file descriptors with the number given in the file name. Opening a file in dev/fd is the same as dup()ing the respective file descriptor. –  Sven Marnach Feb 8 '12 at 20:03

Here's a link to the relevant topic--process substitution--in the bash man page.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.