Simon wrote:
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Peter Rundle
Sent: Wed, 11. May 2005 2:11 PM
To: SLUG
Subject: Re: [SLUG] Script Help
Simon scribed;
Why is the following script ripping out every directory rather than
just those in 'studentfile'
#!/bin/bash
while read name; do
cd $name
rm -fvr *
cd ..
rmdir $name
done < studentlist
Repeat after me: "Never use a star with rm -r !"
Ahhhhh, exactly what happened. OK, I have given myself six of the best
and promise never to do that again!
Can I get some credit for being able to restore them from the backup
:-)
In C, one wouldn't (I hope) call a function and then ignore possible
error return, i.e.
if (chdir(path) == 0)
{
/* do your thang */
}
else
{
/* handle error: see errno */
}
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
cheers
rickw
--
_________________________________
Rick Welykochy || Praxis Services
People who enjoy eating sausage and obey the law should not watch either being
made.
-- Otto von Bismarck
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html