[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How Bash can delete wildcard with exceptions
From: |
alex xmb ratchev |
Subject: |
Re: How Bash can delete wildcard with exceptions |
Date: |
Sat, 1 Jul 2023 13:34:56 +0200 |
On Sat, Jul 1, 2023, 13:05 alex xmb ratchev <fxmbsw7@gmail.com> wrote:
>
>
> On Sat, Jul 1, 2023, 11:34 Budi <budikusasi@gmail.com> wrote:
>
>> How Bash can delete wildcard with exceptions e.g. deletion below
>> except delete FOO.BAR
>>
>> $ ls
>>
>> BOO.BAR
>> MOO.BAR
>> COO.BAR
>> FOO.BAR
>> JOO.BAR
>> NOO.BAR
>> ZOO.BAR
>> BOO.BAZ
>> MOO.BAZ
>> COO.BAZ
>> JOO.BAZ
>> FOO.BAZ
>> NOO.BAZ
>> ZOO.BAZ
>>
>> tried:
>> $ shopt -s extglob globstar
>>
>> $ rm *.BAR !(FOO.BAR)
>>
>> not work, it wiped all! Help!
>>
>
> shopt -s extglob dotglob
>
> rm !(FOO.BAR)
>
shopt -s extglob dotglob
mkdir t2 ; cd t2 ; eval \>{1..9} ; ls ; rm !(1|2|3) ; ls ; cd .. ; rm -rf t2
1 2 3 4 5 6 7 8 9
1 2 3
m=( 4 5 6 ) m=( "${m[@]@Q}" ) IFS=\| M=${m[*]} IFS=$' \t\n' ; mkdir t2 ; cd
t2 ; eval \>{1..9} ; ls ; declare -a "r=( !($M) )" ; declare -p r M ; rm
"${r[@]}" ; ls ; cd .. ; rm -rf t2
1 2 3 4 5 6 7 8 9
declare -a r=([0]="1" [1]="2" [2]="3" [3]="7" [4]="8" [5]="9")
declare -- M="'4'|'5'|'6'"
4 5 6
>