help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with pattern matching needed


From: Greg Wooledge
Subject: Re: help with pattern matching needed
Date: Wed, 12 Jan 2022 07:38:21 -0500

On Wed, Jan 12, 2022 at 06:33:02AM +0100, Christoph Anton Mitterer wrote:
> $ cat circumflex-test 
> case "$1" in
> (['^.a'])
>       echo match
>       ;;
> (*)
>       echo else
> esac

> $ sh run-circumflex | paste - - - - | column -t
> dash:        match  else   else
> busybox-sh:  match  else   else

> Does anyone have any explanation for this (other than it being a bug in
> dash/busybox-sh[0])?

The quotes are irrelevant; you should get the same results if you
remove them.

POSIX only specifies ! as the negation character for [...] ranges in globs.
Some shells also permit ^ to be used, for the comfort of people who are
used to regular expressions.  Bash is one of the shells that permit ^.

The behavior of dash has changed in recent years.  On Debian 11:

unicorn:~$ dash
$ case a in [^.a]) echo match;; *) echo not;; esac
not

But if I perform that same test on a much older Debian system, I get
the result "match" -- because the ^ is not treated as a range negation
character in that version.

Presumably your system is using one of the older versions of dash.  The
results you see are not a bug in dash.  Your expectations are simply
wrong.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]