0
awk '{print FILENAME, $0}' <(ls)  # output:   /dev/fd/4 file
awk '{print FILENAME, $0}' < <(ls) # output:   - file

In the above one-liners, the first one generates file descriptor and then the filename where as the second one generates the hypen (-) character and then the filename. Why this behavior?

1 Answer 1

1

You can see it this way:

awk '{print FILENAME, $0}' <(ls)
# is the same as
awk '{print FILENAME, $0}' output_of_ls_command

awk will read a tmp file (created by bash, let's name it as output_of_ls_command(it's /dev/fd/4 in your case))


awk '{print FILENAME, $0}' < <(ls)
# is the same as
awk '{print FILENAME, $0}' < output_of_ls_command

awk will read stdin (bash read the tmp file, and send the content to awk, FILENAME is -)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.