On 17 Oct 2006, Sonia Hamilton <[EMAIL PROTECTED]> wrote:
> I've written a small script that archives email - it works, but I was
> wondering if there's any better way to write it (apart from using
> another language).
>
> The script is:
>
> > for i in z_bak:7 root:14 y_spam_definite:56 ; do
> > mydir=${i%:*}
> > mydays=${i#*:}
>
> $mydir is the directory to cleanup, $mydays is the # of days I want to
> keep email. Is there any better way of writing the for loop to go thru
> the 2 sets of values?
Using associative arrays in zsh (or ksh or maybe bash?) you can write
typeset -A to_archive
to_archive=(z_bak 7 root 14 y_spam_definite 56)
for mydir in ${(k)to_archive}
do
mydays=$to_archive[$mydir]
But I've actually never used them before doing this, and I have to say
the ${(k)to_archive} is beyond my current tolerance for shell wierdness.
--
Martin
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html