From 45ca80e0e1509c613f05cdb5fe8ec1157a4a7a48 Mon Sep 17 00:00:00 2001
From: Laurent Bercot
Date: Fri, 26 Nov 2021 07:00:11 +0000
Subject: Add shell matching option to case
Signed-off-by: Laurent Bercot
---
doc/case.html | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
(limited to 'doc')
diff --git a/doc/case.html b/doc/case.html
index a82eec8..8ae817b 100644
--- a/doc/case.html
+++ b/doc/case.html
@@ -31,7 +31,7 @@ matches.
- case [ -E | -e ] [ -i ] [ -n | -N ] value
+ case [ -S | -s ] [ -E | -e ] [ -i ] [ -n | -N ] value
{
[ regex { prog... } ]
[ regex { prog... } ]
@@ -57,6 +57,13 @@ is empty.
Options
+ - -s : Shell matching. The regex words will not be
+interpreted as regular expressions, but as shell expressions to be interpreted
+via fnmatch().
+The other options also change meanings, see the Shell matching section below.
+ - -S : Regular expression matching. This is the default. This
+section, and all of the sections below except the Shell matching one,
+assumes that it is the case.
- -e : Interpret the regex words as
basic
regular expressions.
@@ -116,6 +123,41 @@ to the output of the /usr/bin/env command:
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:
+
+
+
+ - Subexpression matching is always disabled.
+ - prog... is always executed with an unmodified environment.
+ - The options to the case command change meanings: instead of
+controlling how the regex regular expressions are interpreted by the
+regcomp()
+primitive, they now control how value is matched against the regex patterns
+(which are not regular expressions!) via the
+fnmatch()
+primitive. Namely:
+
+ - -e : Treat a backslash as an ordinary character; do not allow
+character escaping in patterns. (This sets the FNM_NOESCAPE flag.)
+ - -E : Allow backslash escaping in patterns. This is the default.
+(This clears the FNM_NOESCAPE flag.)
+ - -i : Treat a period (.) as a special character for
+matching (set FNM_PERIOD). By default, the period is not a special character
+(FNM_PERIOD is cleared).
+ - -N : Treat patterns as pathnames: make slashes character special.
+(This sets the FNM_PATHNAME flag.)
+ - -n : Do not treat patterns as pathnames (clear the
+FNM_PATHNAME flag). This is the default.
+
+
+
Notes