execline
Software
skarnet.org

The case program

case compares a value against a series of regular expressions, and executes into a program depending on the first expression the value matches.

Interface

In an execlineb script:

     case [ -S | -s ] [ -E | -e ] [ -i ] [ -n | -N ] value
     {
       [ regex { prog... } ]
       [ regex { prog... } ]
       ...
     }
     progdefault...

Options

Subexpression matching

If the -N option has been given, and value matches a regex, then case will run prog with a modified environment:

To retrieve that information into your command line in an execline script, you can use the elgetpositionals program.

An example

Consider the following script; say it's named match.

#!/bin/execlineb -S1
emptyenv
case -N -- $1
{
  "([fo]+)bar(baz)" { /usr/bin/env }
}

Running match foooobarbaz will print the following lines, corresponding to the output of the /usr/bin/env command:

#=2
0=([fo]+)bar(baz)
1=foooo
2=baz

Shell matching

If the -s option has been given to case, then the regex words are not interpreted as regular expressions, but as shell patterns, as is performed by the shell's case conditional construct. This has the following consequences:

Notes