tech-userlevel archive

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

Re: shell (/bin/sh) pattern matching bugs

On Sun, Jun 24, 2018 at 09:55:25PM +0700, Robert Elz wrote:
>     Date:        Sun, 24 Jun 2018 15:52:21 +0200
>     From:
>     Message-ID:  <>
>   | It's a mess... 
> Yes...
>   | Wouldn't it be simple for POSIX to let the case...esac
>   | as is and introduce a ecase...esac[e] (à la grep, egrep) with something
>   | making more sense for corner cases?
> It might be rational for someone to do that, but it won't be posix
> which simply writes down what the standard is (what users can
> depend upon working) - they don't (at least most of the time)
> start inventing new stuff.
> In general, none of this really matters all that much - almost certainly
> not enough for some shell to implement something new, and then for
> it to be copied enough other places for it to be considered standard -
> it is all really just corner cases that the standard has to (attempt to)
> specify properly so as not to mess up the cases that people actually
> use.    That's why, despite those 14 tests failing (assuming they are
> testing what should happen) no real scripts actually fail.
> And wrt the ps in your previous message ...
>   | PS: I don't know if you have already modified the sh(1) man page
> You can check at
> which allows you to view man pages of a whole host of systems, and
> versions.
> What we have now about this is ...
>      The syntax of the case command is
>            case word in
>            [(] pattern ) [ list ] ;&
>            [(] pattern ) [ list ] ;;
>            ...
>            esac
>      The pattern can actually be one or more patterns (see Shell Patterns
>      described later), separated by "|" characters.
> There's no explicit mention in the text of the optional '(' in the patterns
> (which is in posix too) - it is a pure noise character (its presence or absense
> changes nothing) - I think it was invented in ksh (the real one), and is there
> simply to allow editors that indicate matching () [] {} (etc) to not get confused
> by an excess number of ')'s in the file.   I use it sometimes, and omit
> it other times, depending entirely on my mood at the time - and to a
> degree, how long the particular case expression is likely to remain
> around - if it is likely to be a stable script, I am nore likely to include
> that '(' than I do in truly "one off" scripts.
> kre

Thanks for the explanations! I do like reading your messages and
contributions since I have more than once learned that I was making
assumptions about sh(1) that were simply wrong (and writing a fair
amount of scripts, I do stumble occasionally on corner cases or
differing implementations)...

Best regards,
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C

Home | Main Index | Thread Index | Old Index