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 05:11:34PM +0700, Robert Elz wrote:
> Hi all,
> I am soon going to add an ATF test for sh pattern matching (it tests all
> 3 forms, glob expansion, case patterns, and ${var#patern})
> [97] var="[:alpha:]"; case "[" in (["$var"]) printf M;; (*) printf X;; esac
> [97] Expected output 'M', received 'X'

Can you explain why you expect success ("M") in this case? From my basic
understanding of how the shell processes, I expect:

- Substitution of the value of $var in (["$var"]) resulting in:
- [Suppression of the double quotes? But this doesn't change anything in
the bracket expression];
- Then interpretation of the bracket expression.

But then "[" is not an alpha, so it correctly fails...

Could you explain why you think otherwise?

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