Yeah, I replied, but not to the list. It follows: // begin reply //
Still, the previous reply makes an interesting point that I overlooked. Using star in "rm -r" is reckless, in general. But by issuing a "rm -rf $name" will remove the directory along with it's contents, whereas "rm -rf $name/*" wipes only the content out. Up to you to decide what's best. A little bit paranoia =) , but since the subject always leaves us a bunch of options, maybe it's worth mentioning: given the fact that this is probably a non-interactive app, we're assuming a line will never contain a front-slash plus some other folder name. One fine day, the app finds a line containing "/etc", you'll end up removing /etc/*. Empty lines should not be a problem because bash (and I don't know what's the behavior of shells in this case) will ignore them. That goes with the user you're running the script as, possibility of such line getting into the file, and lots of things you guys probably know. My "I-owe-you-2-cents" tip. Cheers. // end reply // On 5/11/05, Alexander Samad <[EMAIL PROTECTED]> wrote: > On Wed, May 11, 2005 at 02:10:40PM +1000, Peter Rundle wrote: > > 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 !" > > > > 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 > > might be best to do this incase there are special characters in the > directory name ! > > 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 > > > > > BodyID:116513997.2.n.logpart (stored separately) > > -- > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ > Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html > > -- Julio C. Ody http://rootshell.be/~julioody -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
