> -----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 your script what will happen if there is a name in the list that > doesn't exist as a directory? > cd $name will fail leaving you in the current directory. > rm -r * will then remove everything in the current directory...... > > as Vino said do this; > > while read name; do > rm -fvr $name > done < studentlist > > much safer. > > HTH > > P > > -- > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
