如何将两个输入传递给同一个命令?

How to pipe two inputs to the same command?

我想要 运行 接受两个参数的命令,这两个参数可以是文件路径或 - 从标准输入读取内容。

示例:

convert file1.txt file2.txt
cat file1.txt | convert - file2.txt
cat file2.txt | convert file1.txt -

所有三个命令都会产生相同的结果。

有没有办法通过管道输入两个参数的输入?

我问这个的原因是因为我想避免将文件系统用于 运行此任务。

您可以使用 process substitution:

convert <(cat file1.txt) <(cat file2.txt)