Phùng Đông Hưng Phùng Đông Hưng - 1 year ago 100
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?

Answer Source

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

Incorporated better example from the comment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download