<<< Date Index >>>     <<< Thread Index >>>

Re: Reliable/safe way of removing empty maildirs?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday, December  6 at 11:40 AM, quoth Paul Hoffman:
>> chmod a-w dir/new
>> if [ `find dir -type f` ] ; then
>
> You have to do something like this instead:
>
> found=`find dir -type f`
> if -n "$found" ; then
>
> At least on my system (Mac OS X 10.3 = Darwin 7.9.0), where find(1) 
> exits with status 0 even if nothing is found.

That's why I used the form that I used. Consider what I said; I said

     if [ `find dir -type f` ] ; then

I did not say:

     if find dir -type f ; then

The reason is because the former relies on the output of find, and the 
latter relies on the exit status of find. In other words, I had 
already addressed this issue. At worst, some shells might require that 
to be rewritten like this:

     if [ "$( find dir -type f )" ] ; then

The reason for that is that [ (also known as /bin/test, and frequently 
a builtin shell command) returns true if it has any arguments of any 
non-zero length, and returns false if it does not (i.e. the -n 
argument is the default behavior). My example is equivalent to this:

     found=`find dir -type f`
     if [ "$found" ] ; then

...but does not require the extraneous variable definition.

Your alternative suggestion:

     if -n "$found" ; then

will, unfortunately, not work in many situations because in many POSIX 
shells (including bash), "-n" is not a valid argument to the "if" 
keyword, nor is "-n" a recognized executable program or command. 
Perhaps in your system you have a /bin/-n program, but most folks 
don't.

~Kyle
- -- 
Many who claim to have been transformed by Christ's love are deeply, 
even murderously, intolerant of criticism.
                                                          -- Sam Harris
-----BEGIN PGP SIGNATURE-----
Comment: Thank you for using encryption!

iD8DBQFHWDXJBkIOoMqOI14RAj1CAJsETNaVb1dj9M9kNyvsy1tKjcHD2QCfRZVu
+DLO3JgxGFwm5u70aTy7BU4=
=Xgwv
-----END PGP SIGNATURE-----