Bash Question

linux: store last command into variable

I'm about to store last command into a variable.

E.g:

#last command:
$> cp myfile /to/somewhere
$> last = #some magical command here
$> echo $last
cp myfile /to/somewhere


I tried several way on
!!:p
command, it does get me last command but I can't store it to variable.

$> last=`!!:p`
$> echo $last
(empty)


Any help?

Answer

Try some_var=$(fc -nl -1), fc command can be used to retrieve previous command

Incorporated better example from the comment.

Comments