awk '{print FILENAME, $0}' <(ls) # output: /dev/fd/4 file
awk '{print FILENAME, $0}' < <(ls) # output: - file
在上面的单行中,第一个生成文件描述符,然后生成文件名,其中第二个生成hypen( - )字符,然后生成文件名。为什么会出现这种情况?
答案 0 :(得分:1)
你可以这样看:
awk '{print FILENAME, $0}' <(ls)
# is the same as
awk '{print FILENAME, $0}' output_of_ls_command
awk
会读取一个tmp文件(由bash
创建,我们将其命名为output_of_ls_command
(在您的情况下为/dev/fd/4
))
awk '{print FILENAME, $0}' < <(ls)
# is the same as
awk '{print FILENAME, $0}' < output_of_ls_command
awk
将读取标准输入(bash
读取tmp文件,并将内容发送至awk
,FILENAME
为-
)