有人问如何将两个命令的输出作为文件传递给另一个命令,他们得到了下面的答案。
( cmd1 | ( cmd2 | ( main_command /dev/fd/3 /dev/fd/4 ) 4<&0 ) 3<&0 )
Run Code Online (Sandbox Code Playgroud)
我需要拆开这个。
假设我有一个文本文件some_file
,我希望将它作为输入传递给main_command
. main_command
将两个文件作为输入。如果我想main_command
与some_file
命令的输出一起使用cmd2
,一种方法是
( cmd2 | ( main_command some_file /dev/fd/4 ) 4<&0 )
Run Code Online (Sandbox Code Playgroud)
main_command some_file /dev/fd/4
. 这只是将文件some_file
和/dev/fd/4
作为参数传递
给main_command
.4<&0
部分表示stdin
将指向文件描述符4
。cmd2 |
将 的输出cmd2
与后面任何内容的输入连接起来。我的问题是:
编辑:我应该说如果我的逻辑是正确的,那么就没有必要回答 1。