dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] expand: Recognize '^' as a negation character in BE
@ 2021-07-16  9:42 Dimitar Yurukov
  2021-07-16 10:00 ` Harald van Dijk
  2021-07-16 12:50 ` [PATCH v2] " Dimitar Yurukov
  0 siblings, 2 replies; 5+ messages in thread
From: Dimitar Yurukov @ 2021-07-16  9:42 UTC (permalink / raw)
  To: dash; +Cc: Dimitar Yurukov

While parsing bracket expression ('[...]'), DASH recognizes only '!' as
a special character for negation/inversion, but POSIX specifies '^'.

The POSIX specification (2018 edition) states:

  ^ The <circumflex> shall signify a non-matching list expression when
    it occurs first in a list, immediately following a
    <left-square-bracket> (see RE Bracket Expression).

DASH:
    $ i='123 asd' && printf "%s\n" "${i##*[!a-z]}"
    asd
    $ i='123 asd' && printf "%s\n" "${i##*[^a-z]}"
    <empty expansion>

BASH (with --posix):
    $ i='123 asd' && printf "%s\n" "${i##*[!a-z]}"
    asd
    $ i='123 asd' && printf "%s\n" "${i##*[^a-z]}"
    asd

Make <circumflex> ('^') a special character used to specify
negation/inversion in bracket expressions:

    $ i='123 asd' && printf "%s\n" "${i##*[^a-z]}"
    asd

Signed-off-by: Dimitar Yurukov <mscalindt@gmail.com>
---
 src/expand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/expand.c b/src/expand.c
index 1730670..06392ff 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1565,7 +1565,7 @@ pmatch(const char *pattern, const char *string)
 
 			startp = p;
 			invert = 0;
-			if (*p == '!') {
+			if (*p == '!' || *p == '^') {
 				invert++;
 				p++;
 			}
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-19  5:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-16  9:42 [PATCH] expand: Recognize '^' as a negation character in BE Dimitar Yurukov
2021-07-16 10:00 ` Harald van Dijk
2021-07-16 12:46   ` Dimitar Yurukov
2021-07-16 12:50 ` [PATCH v2] " Dimitar Yurukov
2021-07-19  5:13   ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).