![](/img/trans.png)
[英]How to redirect multiple inputs from files to a binary being debugged in gdb?
[英]How to redirect one of several inputs?
在Linux / Unix命令行中,当使用具有多个输入的命令时,如何重定向其中之一?
例如,假设我使用cat
连接多个文件,但是我只想要一个文件的最后几行,所以我的输入是testinput1
, testinput2
和tail -n 4 testinput3
。
如何在没有任何临时文件的情况下一行完成此操作?
我尝试了tail -n 4 testinput3 | cat testinput1 testinput2
tail -n 4 testinput3 | cat testinput1 testinput2
,但这似乎只是接受输入1和2。
对不起,标题不好,我不确定如何准确说出它。
bash不会尝试将tail
的输出通过管道传递给cat
,而是提供了进程替换 ,在该进程中,其替换或输入或输出连接到FIFO或/dev/fd
的文件(例如您的终端tty),从而运行进程替换。 这使您可以将进程的输出视为文件。
通常情况下,通常将过程替换的输出重定向到一个循环中,例如, while read -r line; do ##stuff; done < <(process)
while read -r line; do ##stuff; done < <(process)
while read -r line; do ##stuff; done < <(process)
。 但是,在您的情况下, cat
将文件本身作为参数而不是从stdin
读取,因此您省略了初始重定向,例如
cat file1 file2 <(tail -n4 file3)
因此,请熟悉两种形式;如果需要将流程重定向为输入,请熟悉< <(process)
如果您需要将流程的结果视为文件,则请简单地<(process)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.