Re: Checking if directory is empty in postrm
Marcus Brinkmann writes:
> [ `ls -1 $dir` ]
> This does not work. If the dir contains no file, it is "[ ]",
> which returns 0, which is fine. If it contains more than one file, it is too
> many arguments, therefore returning 1, which is also fine. But if it
> contains one file, it returns 0, which is wrong.
Should read:
[ "`ls -1A $dir`" ]
This returns '1' if the directory is empty and '0' otherwise. It is not
tricked by spaces or other unusual characters in file names.
--
John Hasler This posting is in the public domain.
john@dhh.gt.org Do with it what you will.
Dancing Horse Hill Make money from it if you can; I don't mind.
Elmwood, Wisconsin Do not send email advertisements to this address.
Reply to: