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 [ -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

Notes