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 ] value
{
[ regex { prog... } ]
[ regex { prog... } ]
...
}
progdefault...
- case reads an argument value and a sequence of
directives in a block.
- Each directive is a regular expression followed by a block.
- case matches value against the regular expressions
in the order they are given.
- As soon as value matches a regex, case
executes into the prog... command line that immediately follows
the matched regex.
- If value matches no regex, case
eventually execs into progdefault....
Options
- -e : Interpret the regex words as
basic
regular expressions.
- -E : Interpret the regex words as
extended
regular expressions. This is the default.
- -i : Perform case-insensitive matches.
- -n : Do not transmit the matching expression and
subexpressions to prog... via the environment. This is the default.
- -N : Make the matching expression and
subexpressions available to prog's environment.
Subexpression matching
If the -N option has been given, and value matches a regex,
then case will run prog with a modified environment:
- The 0 variable will contain the regex that value matched.
- The # variable will contain the number of subexpressions in regex.
- For every integer i between 1 and the number of subexpressions (included), the
variable i contains the part of value that matched the ith subexpression
in regex.
To retrieve that information into your command line in an execline script, you can use the
elgetpositionals program.