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