Phùng Đông Hưng Phùng Đông Hưng - 7 months ago 41
Bash Question

linux: store last command into variable

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


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

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

$> last=`!!:p`
$> echo $last

Any help?


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

Incorporated better example from the comment.