Reusing output from last command in Bash

后端 未结 13 2064
长情又很酷
长情又很酷 2020-12-07 08:35

Is the output of a Bash command stored in any register? E.g. something similar to $? capturing the output instead of the exit status.

I could assign the

13条回答
  •  萌比男神i
    2020-12-07 08:44

    I have an idea that I don't have time to try to implement immediately.

    But what if you do something like the following:

    $ MY_HISTORY_FILE = `get_temp_filename`
    $ MY_HISTORY_FILE=$MY_HISTORY_FILE bash -i 2>&1 | tee $MY_HISTORY_FILE
    $ some_command
    $ cat $MY_HISTORY_FILE
    $ # ^You'll want to filter that down in practice!
    

    There might be issues with IO buffering. Also the file might get too huge. One would have to come up with a solution to these problems.

提交回复
热议问题