EDIT: You can do this in POSIX-compliant fashion with the fix command tool fc
:
fc 77 79
This will open your editor (probably vi
) with commands 77 through 79 in the buffer. When you save and exit (:x
), the commands will be run.
If you don't want to edit them and you're VERY SURE you know which commands you're calling, you can use:
fc -e true 77 79
This uses true
as an "editor" to edit the commands with, so it just exits without making any changes and the commands are run as-is.
ORIGINAL ANSWER:
You can use:
history -p \!{77..79} | bash
This assumes that you're not using any aliases or functions or any variables that are only present in the current execution environment, as of course those won't be available in the new shell being started.
A better solution (thanks to Michael Hoffman for reminding me in the comments) is:
eval "$(history -p \!{77..79})"
One of the very, very few cases where eval
is actually appropriate!
Also see:
!77 ; !78 ; !79
okay?!77-79
)