Reputation: 489
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?
Upvotes: 1
Views: 109
Reputation: 247012
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.
If you want it to persist, then you have no choice but to write it to disk
startmem () { sed '/^endmem/Q' > ~/.mem_commands; }
mem () { source ~/.mem_commands; }
But at this point, why don't you just create ~/bin/mem
, add ~/bin
to your PATH, and just edit the mem
file when you want to change it.
Upvotes: 3