#!/bin/bash
srcPath=””
dstPath=””
ErrMsg=”Yout enter the directory or file dose not exist. ”
DstDirMsg=”Please input destination dircetory”
SrcFilesMsg=”Please input source dircetory or file.”
DstFilesMsg=”Delete the file or dircetory. ”
DirFileMsg=””
function inputSourcePath(){
while true
do
echo DirFileMsg
read srcPath
if [ -dsrcPath -o -f srcPath ]; then
if [ -esrcPath ]; then
break
fi
fi
echo “ErrMsg”
done
}
function inputDstPath(){
while true
do
echoDstDirMsg
read dstPath
if [ -d dstPath -a -edstPath ]; then
break
fi
echo “ErrMsg”
done
}
function copy(){
while true
do
inputSourcePath
inputDstPath
if [ srcPath != dstPath -a -dsrcPath ]; then
break
elif [ -f $srcPath -a dirname $srcPath
!= dstPath ]; then
break
fi
echo “The source and destination cannot be the same! Please input again”
done
cp -a srcPath dstPath
echo “The files have been susscessfully copied.”
}
function delete(){
inputSourcePath
echo “Proceed with removal? y”
read yn
if [yn “y” ]; then
rm -rf $srcPath
echo “sussessfully delete!”
fi
}
function backup(){
inputSourcePath
inputDstPath
backName=date -d today +%Y%m%d%H%M%S
cd dstPath
tar -czvf “backName.tar.gz” srcPath
echo “A successful backup todstPath/backName.tar.gz”
}
while true
do
echo “*******************************************”
echo ” 1 Copy”
echo ” 2 Delete”
echo ” 3 Backup”
echo ” 4 Quit ”
echo “*******************************************”
read op
caseop in
1)
echo “You selection is Copy”
DirFileMsg=SrcFilesMsg
copy
read -p “Press any key to continue…”
clear
;;
2)
echo “You selection is delete”
DirFileMsg=DstFilesMsg
delete
read -p “Press any key to continue…”
clear
;;
3)
echo “You selection is Back”
DirFileMsg=$SrcFilesMsg
backup
read -p “Press any key to continue…”
clear
;;
4)
echo “Exit…”
break
;;
*)
echo “Error! invalide selection, try again”
;;
esac
done
本文链接:http://www.geekyunwei.com/1855.html
网友评论comments