* "Wu, Yue" <vano...@gmail.com> [2009-09-24 09:24 +0800]:
> Thanks for all replies, mutt uses its own maildir so I have no
> issue about the two apps read/write the same maildirs at one
> time.
> 
> I don't know sh, and I've tried the following sh script, but it
> doesn't work:
> 
> #!/bin/sh
> 
> DIR="~/temp/mails/*"
> 
> for d in ${DIR}; do
>         if [ $(find d -type f | wc -l) -eq 0 ] ; then
>                 rm -r d
>         fi
> done
> 
> It says:
> 
> y...@bsd ~ > ./del_maildir.sh
> find: d: No such file or directory
> rm: d: No such file or directory
> y

Without a '$' prefix, 'd' is interpreted as a string and not a
variable.  There are a few improvements I would make such as
quoting variables and moving the glob (*) into the for statement.

#! /bin/sh

DIR=~/temp/mails

for d in "$DIR/"*
do
        if [ "$(find "$d" -type f -print | wc -l)" -eq 0 ]
        then
                rm -r "$d"
        fi
done

Reply via email to