Using output of previous commands in bash

Viewed 15026

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, I run a make which gives warnings, but I want to find all warnings. So, I type

make | grep "warning"

but I'm not able to see the output of the make then.

I would like to type something like this instead:

make
% | grep "warning"
5 Answers

You could do this:

make
!! | grep "warning"

By using !! you tell it to repeat the last command in that spot, along with any other bash commands you want to add to it.

The downside is that if the command you are repeating takes a long time to execute, you'll have that much longer to wait unless you stored the output of the previous command to an output file first.

Related