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?
Best Answer
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, whichwc
reports. It reports on the file descriptor it was given from which to read.