Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何重定向多个输入中的一个?_Linux_Bash_Unix - Fatal编程技术网

Linux 如何重定向多个输入中的一个?

Linux 如何重定向多个输入中的一个?,linux,bash,unix,Linux,Bash,Unix,在Linux/Unix命令行中,当使用具有多个输入的命令时,如何重定向其中一个输入 例如,假设我使用cat连接多个文件,但我只需要一个文件的最后几行,因此我的输入是testinput1,testinput2,和tail-n4testinput3 如果没有任何临时文件,如何在一行中完成此操作 我尝试了tail-n4testinput3 | cat testinput1 testinput2,但这似乎只接受了输入1和2 很抱歉标题不好,我不知道如何准确地表达它。bash没有尝试将tail的输出通过管

在Linux/Unix命令行中,当使用具有多个输入的命令时,如何重定向其中一个输入

例如,假设我使用
cat
连接多个文件,但我只需要一个文件的最后几行,因此我的输入是
testinput1
testinput2
,和
tail-n4testinput3

如果没有任何临时文件,如何在一行中完成此操作

我尝试了
tail-n4testinput3 | cat testinput1 testinput2
,但这似乎只接受了输入1和2


很抱歉标题不好,我不知道如何准确地表达它。

bash没有尝试将
tail
的输出通过管道传输到
cat
,而是提供了进程替换,其中进程替换的输入或输出连接到
/dev/fd
中的FIFO或文件(如您的终端tty)。这允许您将进程的输出视为一个文件


在正常情况下,您通常会将进程替换的输出重定向到一个循环中,例如,
while read-r line;做事;完成而不是尝试将
tail
的输出通过管道传输到
cat
,bash提供了进程替换,其中进程替换在运行时,其输入或输出连接到一个FIFO或
/dev/fd
中的一个文件(如您的终端tty)。这允许您将进程的输出视为一个文件


在正常情况下,您通常会将进程替换的输出重定向到一个循环中,例如,
while read-r line;做事;完成<您可以使用@ymonad我试过
cat testinput1 testinput2您忘记了父母
@DavidC.Rankin我试过
cat testinput1 testinput2<抱歉,请参阅更新的评论,您不需要额外的重定向
cat file1文件2您可以使用@ymonad I trusted
cat testinput1 testinput2您忘记了父母
@DavidC.Rankin I trusted
cat testinput1 testinput2<抱歉,请参阅更新的评论,您不需要额外的重定向
cat file1文件2
cat file1 file2 <(tail -n4 file3)