Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Lets say my last 3 commands were: % rm foo.out % myprog > foo.out % cat foo.out

I will like to invoke the last 3 with one stroke of the enter key, i.e. do some shell history commands which invke: % rm foo.out && myprog > foo.out && cat foo.out

How can I do this?

share|improve this question
    
my week old answer has 4 upvotes, in what way does it not satisfy you? Gotta work on your acceptance rate, or at least give some feedback if you want to keep getting free help from strangers. –  dbenhur Apr 5 '12 at 5:38
add comment

1 Answer

up vote 6 down vote accepted

History expansion works pretty similarly in bash and zsh, use !-N to reference the Nth previous command

$ echo foo
foo
$ echo bar
bar
$ echo baz
baz
$ !-3 && !-2 && !-1
echo foo && echo bar && echo baz
foo
bar
baz
share|improve this answer
    
+1. If you want to execute all 3 commands regardless of their exit statuses, use ; instead of && –  glenn jackman Mar 30 '12 at 0:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.