dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* possible wrong behaviour with patterns double [ with no closing ]
@ 2022-01-17  3:23 Christoph Anton Mitterer
  2022-01-18  6:18 ` Herbert Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Anton Mitterer @ 2022-01-17  3:23 UTC (permalink / raw)
  To: dash

Hey.


Assuming a pattern of:
[.*^\]
my understanding was that this would actually mean:
- the literal string [. followed by
- the pattern notation special character * (i.e. any string) followed by
- the literal string ^]

Because ] is escaped, it's to be taken literally and in a pattern a [
without corresponding ] is to be taken literally as well.

That seems to work in dash:
$ case '[.^]' in ([.*^\]) echo match;; (*) echo no match;; esac
match
$ case '[.x^]' in ([.*^\]) echo match;; (*) echo no match;; esac
match
$ case '[.xx^]' in ([.*^\]) echo match;; (*) echo no match;; esac
match


However, adding another [ to the pattern:
[.*^[\]
which should be:
- the literal string [. followed by
- the pattern notation special character * (i.e. any string) followed by
- the literal string ^[]

No longer matches:
$ case '[.^[]' in ([.*^[\]) echo match;; (*) echo no match;; esac
no match
$ case '[.x^[]' in ([.*^[\]) echo match;; (*) echo no match;; esac
no match
$ case '[.xx^[]' in ([.*^[\]) echo match;; (*) echo no match;; esac
no match


Whereas, AFAIU POSIX, it should.

This works, btw. in bash, but neither in busybox sh, nor klibc sh.


Cheers,
Chris.

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

end of thread, other threads:[~2022-01-25  3:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17  3:23 possible wrong behaviour with patterns double [ with no closing ] Christoph Anton Mitterer
2022-01-18  6:18 ` Herbert Xu
2022-01-18 14:28   ` Christoph Anton Mitterer
2022-01-24 16:26   ` Christoph Anton Mitterer
2022-01-25  0:36     ` 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).