【问题标题】:How to pipe two inputs to the same command?如何将两个输入通过管道传输到同一个命令?
【发布时间】:2020-08-07 23:37:49
【问题描述】:

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

例子:

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

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

有没有办法为它的两个参数输入输入?

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

【问题讨论】:

    标签: unix pipe stdin


    【解决方案1】:

    你可以使用process substitution:

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

    【讨论】:

    • 这个<() 运算符的名称是什么,或者我在哪里可以找到更多关于它的信息?
    • 这是进程替换。我已经添加了答案的链接
    • 非常感谢! ?
    猜你喜欢
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    相关资源
    最近更新 更多