Using output of previous commands in bash

后端 未结 5 2119
情书的邮戳
情书的邮戳 2021-02-20 00:50

In Mathematica, it is possible to reuse the output of the previous command by using %.

Is something similar possible for bash (or some other shell)?

For example,

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-20 01:07

    Since the amount of output is indeterminate, it doesn't make sense for bash to store it for you for re-display. But there's an alternate solution to your problem:

    The tee command allows you to duplicate an output stream to a file. So if you're willing to use a file for temporary storage, you can do something like this:

    make | tee output.txt
    grep "warning" output.txt
    

    This solution avoids running make twice, which could be (a) expensive and (b) inconsistent: the second make may be doing less work than the first because some targets were already made the first time around.

    Note: I haven't tried this. You may need to fiddle with joining the error and output streams, or such.

提交回复
热议问题