<()在Bash中做什么? [英] What does <() do in Bash?
问题描述
在帖子中在superuser.com上的答案,我们看到
In a post's answer on superuser.com, we see that
join <(sort abc) <(sort bcd)
将对文件abc和bcd进行排序,然后再将它们发送加入.这导致了一个编程问题,更适合于stackoverflow.
will sort files abc and bcd before sending them to join. This leads to a programming question, better suited for stackoverflow.
这是如何工作的?这个<()构造到底是什么?它叫什么?
How does this work? What exactly is this <() construct? What's it called?
如果(sort abc)是在abc上运行sort并返回输出的合法调用,为什么我们需要<
?
If (sort abc) is a legal call that runs sort on abc and returns output, why do we need the <
?
也就是说,以下两行是等效的
That is, the following two lines are equivalent
(sort abc) | join - <(sort bcd)
join <(sort abc) <(sort bcd)
但是
join (sort abc) (sort bcd)
是语法错误.请提示我!
is a syntax error. Please clue me in!
推荐答案
这称为流程替换.
<(
list
)
是单个语法构造,<"在这种情况下,字符不是单独的符号.它执行 list 并将其输出作为某种文件(不是标准重定向)提供给命令.
<(
list
)
is a single syntax construct, the '<' character is not a separate symbol in this case. It executes list and provides its output as sort of a file (not a standard redirection) to the command.
这等同于运行(除了在可能的情况下使用管道而不是临时文件):
It is equivalent to running (except it uses pipes instead of temporary files when possible):
sort abc > /tmp/1
sort bcd > /tmp/2
join /tmp/1 /tmp/2
请注意,两种输出均以文件名的形式提供,而不是作为标准重定向.
Note that the output of both sorts are provided as filenames to join, not as standard redirections.
(
list
)
是出于不同目的的不同构造.它只是创建一个执行 list 的子外壳,并将其标准描述符提供给父外壳.
(
list
)
is a different construct, for a different purpose. It simply creates a subshell that executes list, providing its standard descriptors to the parent shell.
此处是bash中的相关部分手册.
Here is the relevant part in the bash manual.
这篇关于<()在Bash中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!