Bash – Reusing output from last command in Bash

bashstdoutterminal

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…

Best Answer

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