Thursday, July 30, 2009

How to copy the last used command in linux comand prompt?

I figured out that !! placed anywhere in a command will replace it with the last entered command in linux (using bash). But I couldn't copy it to a file or a variable. Please help.

How to copy the last used command in linux comand prompt?
use echo to print


echo !!





use redirection to dump to file


echo !! %26gt; last_command.txt





use two greater-thans to append a file


echo !! %26gt;%26gt; command_list.txt





copying to an environment variable depends on your shell. in csh, it'd be


setenv MYCOMMAND !!





but in bash it'd be something like


export MYCOMMAND=!!
Reply:Args for a script are $0, $1, $2, etc., where $0 is the command to invoke, $1 is first "real" argument, etc. Report It



No comments:

Post a Comment