Pete Pete - 5 months ago 9
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:
mem
, which executes the commands.

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

Answer

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.