> Can someone debug this for me and email me back please, I'm stuck...Need
> your expertise please. Thank you in advance.
> #========================
> # Simple Backup Script
> #========================
> clear
> mkdir -p ~/backup
> LIST=`ls *`
> for name in $LIST
do
Quote:> echo -e "Do you want to backup $name ? \n"
> read reply
> do
do not
Quote:> if [ "$reply" = "y" ]
> then
> cp -f $name ~/backup
> echo "File saved!"
> echo -e "$name was backed up at: `date`" >> backup.log
> elif [ "$reply" = "Y" ]
> then
> cp -f $name ~/backup
> echo "File saved!"
> else
> echo "No file saved."
> fi
> done
> exit 0
Apart from having "do" on the wrong line, your script should work,
though you should enclose $name in quotation marks in case there
are any file names containing spaces.
Here is a more efficient version:
mkdir -p ~/backup
for name in *
do
echo -e "Do you want to backup $name ? \n" ## see below
read reply
case $reply in
[yY]*)
cp -f "$name" ~/backup
echo "File saved!"
echo -e "$name was backed up at: `date`" >> backup.log
;;
*) echo "$name not saved." ;;
esac
done
In bash, I'd use this for the prompt and read lines:
read -n1 -p "Do you want to backup $name ? " reply
Then the user doesn't need to press RETURN.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2002, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License