I've written a shell script (called Trash.sh) that when run will display all the files in my 'dustbin' directory and ask the user if they wish to delete each file one by one. The script is as follows:
#if directory is empty, display message
if test ! -f ~/dustbin/*
then
echo "Directory is empty"
#if directory is not empty, then display each item and ask to delete
else
for resfile in ~/dustbin/* #for each file in directory, store it in resfile variable
do
if test -f $resfile ; then #if a file exists
echo "Do you want to delete $resfile?"
echo "Enter y or n"
read ans #store user input in ans variable
if test $ans = y ; then
rm $resfile
echo "File $resfile was deleted"
fi
fi
done
fi
This works fine for me. When a user types sh Trash.sh
the script will run fine, each file will be displayed and teh user will be asked to delete it or not. However what I would like to add is the option for the user to type sh Trash.sh -a
and for all the files in the directory to be automatically deleted without confirmation.
I'm a bit stuck at how to achieve this. Any ideas?
ps - I'm using Mac OS X 10.6.4 and doing everything through Terminal