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

Re: Bookworm: dash shell globs don't recognise [^...] to negate a character class



On Thu, Apr 13, 2023 at 12:12:23AM +0000, David wrote:
> $ echo [^0-9]*
> 11 22           <------ new behaviour by dash

The [^chars] syntax is a negation in Basic and Extended Regular
Expressions, and in bash's globs (it's a bash extension), but NOT in
POSIX globs.

The correct negation syntax in POSIX sh globs is [!chars].

This goes all the way back to the original Bourne shell, where the ^
character was a synonym for | (pipe), because many terminals did not
have a | character.  Due to the way sh parses commands, using ^ in
globs would have caused problems.  That's why sh uses [!chars].


Reply to: