[Top][All Lists]

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

Re: Bash extended glob - Negation

From: Chet Ramey
Subject: Re: Bash extended glob - Negation
Date: Fri, 30 Apr 2021 09:32:54 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.0

On 4/30/21 2:58 AM, Inian Vasanth wrote:

Bash Version: 5.1
Patch Level: 4
Release Status: release


A wildcard expression after a negate extglob construct is not returning
right results.


Consider the following files and assume, that I want to exclude files
ending with 8

shopt -s extglob
touch atop_20210330 atop_20210427 atop_20210428
ls -1 atop_20210@(3|4)+([0-4])!(8)

But when I add an extra * at the end of the expression like

ls -1 atop_20210@(3|4)+([0-4])!(8)*

Why is it the case? Shouldn't the glob expression just serve the !(8)
pattern to exclude and simply do a no-op for the extra * character?

Don't assume the !(8) has to match one character; it can match zero.
If you want to make sure to match filenames ending in something other
than 8, use an operator like [!8] that will match one character.

``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/

reply via email to

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