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
> 

Attachment: signature.asc
Description: Digital signature

-- 
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