【问题标题】:How to concatenate stdin in to a pipe?如何将标准输入连接到管道?
【发布时间】:2016-02-15 17:37:51
【问题描述】:

我想将管道和标准输入的输出发送到 bash 中的管道。

即:

gen_input | cat - | parse_input_and_stdin

会将gen_input 的输出发送到parse_input_and_stdin,然后让标准输入保持打开状态以进行更多交互输入。

【问题讨论】:

    标签: bash shell


    【解决方案1】:

    关闭。

    { gen_input ; cat ; } | parse_input_and_stdin
    

    【讨论】:

    • 这个也行,但我选择了另一个,因为它更明显。
    • 这种形式使得连接两个以上源的输出变得更加简单。继续在分号之间添加它们。
    【解决方案2】:
    cat <(gen_input) - | parse_input_and_stdin
    

    【讨论】:

    • 优秀!谢谢!
    • 这非常适合测试我的 post-receive 钩子 ;) 因为我需要分别用 $from$to$branch 喂它,所以我做了:cat &lt;(git log -2 --format=oneline --reverse | awk '{print $1}' | tr '\n' ' ') - | ./hooks/post-receive,另外提供通过键入分支,然后按 CTRL+D。伟大的! ;).
    • 非常有用!这有助于我用一些已知的输入为程序提供输入,然后继续以交互模式从标准输入提供它。谢谢这个漂亮的宝石!
    猜你喜欢
    • 2012-03-11
    • 2022-01-08
    • 1970-01-01
    • 2014-01-04
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    相关资源
    最近更新 更多