execline
Software
www.skarnet.org
runblock's purpose is to help you write execline commands in the execline language. It can only be used inside an execline(b) script. If the script has been given blocks as arguments, runblock allows you to execute one of the blocks individually.
runblock [ -P ] [ -n argshift ] [ -r ] n
Suppose that we want the ifelse command. ifelse takes two blocks and a remainder. It forks and executes the first block; if the result is true, it execs into the second block; else it executes into the remainder. So we can chain ifelse commands to perform a series of tests, like this:
#!/command/execlineb ... ifelse { test $A -eq 1 } { dosomething1 foo } ifelse { test $A -eq 2 } { dosomething2 bar } ifelse { test $A -eq 3 } { dosomething3 baz } dosomethingelse quxinstead of nesting ifthenelse blocks.
runblock allows us to write the ifelse command in the execline language - and the implementation is very simple:
#!/command/execlineb ifthenelse { runblock 1 } { runblock 2 } { runblock -r 2 }That's it.
The runblock idea, as well as the ifelse idea, comes from Paul Jarc.