Hello,

I'm trying to write a simple script to search a directory tree for a 
file pattern (specified as an argument with a wildcard, ie, testfile* or 
*.jpg), and then delete matching files after first prompting the user 
for a y/n. (yes=delete, no=don't delete, find the next match)

The following script works partially in that it seems to find and delete 
the first matching file in a particular directory, but then it leaves 
that directory and goes on and finds/deletes the first match in the next 
directory, etc. (I have not added the prompting part yet- see below.)

#/bin/sh 


find -name "$1" | while read file
  do
        echo "Deleting file:  $file"
        rm $file
  done

exit 0


If I try to add an esac so that it prompts before it deletes, for some 
reason it does not wait for input, but rather skips down to the "Invalid 
choice" command and exits:

#/bin/sh 


find -name "$1" | while read file
  do
        echo "About to delete file:  $file ... Contine?  [y/n]" 
        read ans
        case "$ans" in
                y)      rm $file;;
                n)      echo "Skipping file:  $file.";;
                *)      echo -e "Invalid choice."; exit 1;;
        esac
  done

exit 0


And finally, as a much simpler approach:

#/bin/sh 


find -name "$1" -exec rm -i {} ';'

exit 0

This will find the first matching file (whereupon rm will prompt me to 
delete or not) but then it will exit without searching for more matches.

What am I doing wrong here?  Am I using the wrong tools?  Any advice 
greatly appreciated!

Joe
[EMAIL PROTECTED]




_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to