Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .