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

Re: bash parameter expansion "doesn't like" dots?



On 05/03/2024 05:27, David Wright wrote:
Pattern matching in the shell is not the same as in grep: the
rules are different, but similar enough to confuse.
Grep uses regular expressions, while the shell is usually globs. (I have no experience of shells other than dash and bash though.)
Bash can compare with regexes using the =~ operator [[ $A =~ $B ]] ...

Which shell also matters. The OP appears to be using ^ to negate,
but ! has the advantage that it will be understood in bash and dash.

I think ^ has been deprecated recently. I failed to find a reference on the web just now though.

Testing with dash on Bullseye:
$ v=string
$ echo ${v#*[!s]}
ring
$ echo ${v#*[^s]}
ring

But on Bookworm:
$ v=string
$ echo ${v#*[!s]}
ring
$ echo ${v#*[^s]}
tring

Now the ^ is being treated as just a list member.

With Bash the ^ still seems to be treated as a negator on Bookworm.

So yes, we should be switching to !

--
John


Reply to: