1

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?

0

1 Answer 1

6

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
1
  • +1. If you want to execute all 3 commands regardless of their exit statuses, use ; instead of && Mar 30, 2012 at 0:57

You must log in to answer this question.

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