On Wed, May 11, 2005 at 03:24:58PM +1000, Rick Welykochy wrote:
> In C, one wouldn't (I hope) call a function and then ignore  possible
> error return, i.e.
>  [ .... ]
> So why eschew the same when programming in the shell?
> 
> while read name; do
>    if cd $name; then
>       rm -fvr *
>       cd ..
>       rmdir $name
>    else
>       echo 1>&2 "skipping directory $name: could not cd"
>    fi
> done < studentlist

Don't stop there!  The defensive programmer
might also

        1. quote vars ie. "$name"
        2. ensure all vars are actually define before use i.e. set -u
        3. check the return of all commands, i.e. set -e
        4. perhaps have a trap ERR ' ... ' because of 3.
                e.g. trap 'echo >&2 Internal error $0 line $LINENO' ERR
        5. use a real language :-)

btw, the rmdir is not going to work, because rm * is not going to
remove dotfiles.

Now the tempation might be to do "rm -rf .*".  But that
will remove ".." and much unhappiness will ensue.

Not doing rm -something* is good advice.


Matt




-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to