#!/bin/bash read -p "Do you want to backup file or directory[file/directory]:" OPTION read -p "what is you backup[absolute location and name]:" BACKUP case $OPTION in file) read -p "what is your backup to dir(absolute location):" TODIR1 read -p "what is your backup name:" NAME1 if [ -e $TODIR1/$NAME1 ];then read -p "Do you want to change name[yes/no]:" CHNAME1 case $CHNAME in yes) read -p "what is you change names:" CHNAMES1 mv $TODIR1/$NAME1 $TODIR1/$CHNAMES1 echo "change success" cp $BACKUP $/TODIR1/$NAME ;; no) exit 1 ;; esac else mkdir $TODIR1 cp $BACKUP $TODIR1/$NAME1 fi ;; directory) read -p "what is your backup to dir(absolute location):" TODIR2 read -p "what is your backup name:" NAME2 if [ -e $TODIR2/$NAME2 ];then read -p "Do you want to change name[yes/no]:" CHNAME2 case $CHNAME2 in yes) read -p "what is you change names:" CHNAMES2 mv $TODIR2/$NAME2 $TODIR2/$CHNAMES2 echo "change success" cp -r $BACKUP $TODIR2/NAME2 ;; no) exit 2 ;; esac else mkdir $TODIR2 cp -r $BACKUP $TODIR2/NAME2 fi ;; esac read -p "Do you want to change time by touch[yes/no]:" TOUCH case $TOUCH in yes) touch $BACKUP echo "successfuly" ;; no) echo "waring!next backup continue source file" ;; esac
原文:http://chomper.blog.51cto.com/7866214/1684505