Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Set difference between sets of files
- X-seq: zsh-users 14097
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Set difference between sets of files
- Date: Wed, 06 May 2009 03:11:46 -0700
- In-reply-to: <20090505195410.2b220325@pws-pc>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <94de1b620905050936g442490e4t3da42ac3946cb29@xxxxxxxxxxxxxx> <20090505175739.7b2e4aca@news01> <090505110010.ZM12545@xxxxxxxxxxxxxxxxxxxxxx> <20090505195410.2b220325@pws-pc>
On May 5, 7:54pm, Peter Stephenson wrote:
} Subject: Re: Set difference between sets of files
}
} On Tue, 05 May 2009 11:00:10 -0700
} Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > typeset -A differ
} > eval differ\[${(q)^MASTER_FILES}\]=a
} > eval differ\[${(q)^BACKUP_FILES}\]=b
} > print -l -- ${(k)differ[(R)a]}
}
} I was trying to come up with something that "just works", which is
} difficult if you're manipulating variable substitution and usually ends
} up looking like a bus smash.
Thd following is arcane, but seems to do the trick:
MASTER_FILES=('a[b' '$cd' 'ef}' 'g h' 1 2 3)
BACKUP_FILES=('a[b' '$cd' 'ef}')
typeset -A differ
eval 'differ[${:-'${(q)^BACKUP_FILES}'}]=b'
eval 'differ[${:-'${(q)^MASTER_FILES}'}]=a'
print -l -- ${(k)differ[(R)b]}
I still can't get the "unset" approach to work. (Note I had the order
of operations reversed in my original example, it's the backup less the
master that's wanted in this case.)
The above came from the epiphany that the (shorter to type but longer
to execute)
for f in $BACKUP_FILES; differ[$f]=b
for f in $MASTER_FILES; differ[$f]=a
works fine, merely requiring an additional local "f". So the trick is
to force parameter substitution, thereby subverting the subscript magic
almost-but-not-quite double-quoting.
} ("Bus smash" may be British slang; it indicates ugliness.)
I got the ugliness, but if that's rhyming slang I haven't managed to
un-rhyme it.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author