Reusing output from last command in Bash

memecs picture memecs · Jun 18, 2014 · Viewed 148.9k times · Source

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 output to a variable with:

output=$(command)

but that's more typing...

Answer

ling picture ling · Sep 1, 2014

You can use $(!!) to recompute (not re-use) the output of the last command.

The !! on its own executes the last command.

$ echo pierre
pierre
$ echo my name is $(!!)
echo my name is $(echo pierre)
my name is pierre