6

I have a folder with three files:

$ ls
a  b  c

If I pipe the output of ls to wc, I get the right result:

$ ls | wc -l
3

However, when I specify the input to wc as the output of ls, I get extra text:

$ wc -l <(ls)
3 /dev/fd/63

Can anyone explain to me what is happening?

14

wc will tell you what file it's working on if it's able. With the first one with the pipe it's reading from stdin, not a file, so does not report a filename. The second one, however, you're using process substitution which presents the output of the command as a file, which wc reports. It reports on the file descriptor it was given from which to read.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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