help-bash
[Top][All Lists]
Advanced

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

Re: How Bash can delete wildcard with exceptions


From: Lawrence Velázquez
Subject: Re: How Bash can delete wildcard with exceptions
Date: Sat, 01 Jul 2023 13:42:44 -0400
User-agent: Cyrus-JMAP/3.9.0-alpha0-499-gf27bbf33e2-fm-20230619.001-gf27bbf33

On Sat, Jul 1, 2023, at 7:57 AM, Greg Wooledge wrote:
> On Sat, Jul 01, 2023 at 01:05:46PM +0200, alex xmb ratchev wrote:
>> > tried:
>> > $ shopt -s extglob globstar
>> >
>> > $ rm *.BAR !(FOO.BAR)
>> >
>> > not work, it wiped all! Help!
>
> That's because *.BAR matches all of them, and then !(FOO.BAR) matches
> all but one.  So you passed all but FOO.BAR twice, and FOO.BAR once.
>
>> shopt -s extglob dotglob
>> 
>> rm !(FOO.BAR)
>
> This is the correct answer.

Hm.  That matches all files except FOO.BAR, but I can't help but
think that the OP actually wants to match only *.BAR files sans
FOO.BAR (judging from their original attempt).  If so, they want:

        rm -- !(FOO).BAR

-- 
vq



reply via email to

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