Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #268030

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

From David Wright <deblis@lionunicorn.co.uk>
Newsgroups linux.debian.user
Subject Re: bash parameter expansion "doesn't like" dots?
Date 2024-03-04 21:30 +0100
Message-ID <Ien6F-eqKm-1@gated-at.bofh.it> (permalink)
References <Ien6F-eqKm-3@gated-at.bofh.it> <Ie3Ul-eeVB-5@gated-at.bofh.it> <Ie3Ul-eeVB-3@gated-at.bofh.it> <Ie505-efMg-1@gated-at.bofh.it> <Ie6Sd-egSW-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon 04 Mar 2024 at 11:51:29 (+0900), John Crawley wrote:
> On 04/03/2024 10:07, David Wright wrote:
> > On Sun 03 Mar 2024 at 17:58:53 (-0600), Albretch Mueller wrote:
> > >   bash doesn't seem to like dots too close to brackets:
> > > 
> > >   echo "${_VAR//[^0-9a-zA-Z.,_-]/}"
> > > 
> > >   works fine.
> > > 
> > > On 3/3/24, Albretch Mueller <lbrtchx@gmail.com> wrote:
> > > > _VAR="admissions.piedmont.edu_files?trackid=wnm:1980&PDFfiller=what-is-the-second-fundamental-theorem-of-calculus(1).pdf"
> > > > 
> > > > echo "${_VAR//[^a-zA-Z0-9_-]/}"
> > > > 
> > > > echo "${_VAR//[^a-zA-Z0-9_-.]/}"
> >                               ↑↑↑
> > 
> > That's a range, except that it isn't because it's written backwards.
> > Check for yourself by testing with 9-0 instead of 0-9.
> > 
> So the problem isn't about dots,

It shouldn't be, as there's nothing special about ".", though there's
the mystery of what was said in the OP's quoted post, which we're not
privy to.

> but the handling of the - which has to go last if it isn't to be treated as a range marker.

First or last in the set. I prefer last, because "]" can only go first
in the set to be a matchable character.

> https://www.gnu.org/software/grep/manual/html_node/Character-Classes-and-Bracket-Expressions.html
> says:
> 
> ‘-’
>     represents the range if it’s not first or last in a list or the ending point of a range. To make the ‘-’ a list item, it is best to put it last.

Well, here's a clue as to where the trouble might have arisen.
Pattern matching in the shell is not the same as in grep: the
rules are different, but similar enough to confuse.

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.

Cheers,
David.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: bash parameter expansion "doesn't like" dots? Albretch Mueller <lbrtchx@gmail.com> - 2024-03-04 01:00 +0100
  Re: bash parameter expansion "doesn't like" dots? David Wright <deblis@lionunicorn.co.uk> - 2024-03-04 02:10 +0100
    Re: bash parameter expansion "doesn't like" dots? John Crawley <john@bunsenlabs.org> - 2024-03-04 04:10 +0100
      Re: bash parameter expansion "doesn't like" dots? David Wright <deblis@lionunicorn.co.uk> - 2024-03-04 21:30 +0100
        Re: bash parameter expansion "doesn't like" dots? John Crawley <john@bunsenlabs.org> - 2024-03-05 03:00 +0100
          Re: bash parameter expansion "doesn't like" dots? Greg Wooledge <greg@wooledge.org> - 2024-03-05 03:10 +0100
            Re: bash parameter expansion "doesn't like" dots? John Crawley <john@bunsenlabs.org> - 2024-03-05 03:30 +0100
              Re: bash parameter expansion "doesn't like" dots? Greg Wooledge <greg@wooledge.org> - 2024-03-05 04:00 +0100
                Re: bash parameter expansion "doesn't like" dots? David <bouncingcats@gmail.com> - 2024-03-05 06:30 +0100
                Re: bash parameter expansion "doesn't like" dots? Max Nikulin <manikulin@gmail.com> - 2024-03-05 12:40 +0100
            Re: bash parameter expansion "doesn't like" dots? Max Nikulin <manikulin@gmail.com> - 2024-03-05 03:40 +0100
              Re: bash parameter expansion "doesn't like" dots? John Crawley <john@bunsenlabs.org> - 2024-03-05 04:00 +0100

csiph-web