help-bash
[Top][All Lists]
Advanced

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

Re: case $var in $list) issue


From: Chet Ramey
Subject: Re: case $var in $list) issue
Date: Fri, 1 Nov 2024 10:49:00 -0400
User-agent: Mozilla Thunderbird

On 11/1/24 7:15 AM, Greg Wooledge wrote:
On Fri, Nov 01, 2024 at 06:00:49 +0100, #!microsuxx wrote:
shopt -s extglob
m='@(a|b)' ; case b in $m) echo ye ; esac
ye

Huh, interesting indeed.

It's really not.


hobbit:~$ shopt -s extglob
hobbit:~$ m='a|b'
hobbit:~$ case b in $m) echo ye ; esac
hobbit:~$ m='@(a|b)'
hobbit:~$ case b in $m) echo ye ; esac
ye

I can only speculate that it sometimes re-parses the contents of $m
based on the first character.

The case statement has a pattern list with a single element, $m, which
expands to a single unquoted extglob pattern, @(a|b).

The case statement tries to match b against that pattern, and, since
extglob is enabled, it matches.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]