On Tue, Nov 17, 1998 at 10:15:43AM +0100, Richard Braakman wrote: > Marcus Brinkmann wrote: > > can someone give me a hint how I can efficient test if a certain directory > > is empty in the postrm (shell script)? > > If you only want to know if it's empty because you want to remove it, > then there's a very simple solution: > > rmdir directory 2>/dev/null || true > > The rmdir will fail if it's not empty :) > (You can use its return code if you need to check if it succeeded)
Indeed I want to remove it if it is empty, so this one is the winner, as it produces the least overhead. However, a new question arises. Will this work in all cases: rmdir $LDIR 2>/dev/null && grep -v $LDIR $LDSOCONF >$tmpfile && mv $tmpfile $LDSOCONF || true rm $tempfile # just in case the mv failed, or grep failed partly Or is there any trap door I miss? -- "Rhubarb is no Egyptian god." Debian GNU/Linux finger brinkmd@ Marcus Brinkmann http://www.debian.org master.debian.org [EMAIL PROTECTED] for public PGP Key http://homepage.ruhr-uni-bochum.de/Marcus.Brinkmann/ PGP Key ID 36E7CD09

