Pete Pete - 1 year ago 48
Linux Question

Save Commands Typed To Use later

I'm looking for something that is like this:

$ startmem
$ command1
$ command2
$ command3
$ endmem

Later, I want to call it like this:
, which executes the commands.

To clear, just use
again. Is there a way to to this?


You could do this:

startmem () { eval "mem() { $(sed '/^endmem/Q'); }"; }

That will take your input, up to but not including the "endmem" line, and generate a "mem" function.