From ddfeab1bdc000c586136043d6c82d25199421c26 Mon Sep 17 00:00:00 2001
From: Laurent Bercot
Date: Wed, 11 Aug 2021 09:09:52 +0000
Subject: Better case documentation
Signed-off-by: Laurent Bercot
---
doc/case.html | 44 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 40 insertions(+), 4 deletions(-)
(limited to 'doc/case.html')
diff --git a/doc/case.html b/doc/case.html
index 5340c07..a7d2a84 100644
--- a/doc/case.html
+++ b/doc/case.html
@@ -31,7 +31,7 @@ matches.
- case [ -E | -e | -i | -n ] value
+ case [ -E | -e ] [ -i ] [ -n | -N ] value
{
[ regex { prog... } ]
[ regex { prog... } ]
@@ -50,7 +50,8 @@ in the order they are given.
executes into the prog... command line that immediately follows
the matched regex.
If value matches no regex, case
-eventually execs into progdefault....
+eventually execs into progdefault..., or exits 0 if progdefault...
+is empty.
Options
@@ -63,10 +64,11 @@ regular expressions.
extended
regular expressions. This is the default.
-i : Perform case-insensitive matches.
+ -N : Make the matching expression and
+subexpressions available to prog's environment. See the "Subexpression
+matching" section below.
-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
@@ -89,5 +91,39 @@ in regex.
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:
+
+
+0=\([fo]+\)bar\(baz\)
+#=2
+1=foooo
+2=baz
+
+
+ Notes
+
+
+ - value must match regex as a full word. If only a substring of value
+matches regex, it is not considered a match.
+ - If value matches no regex, progdefault... is always executed with an
+unmodified environment, whether subexpression matching has been requested or not.
+
+