#!/bin/sh if [ $# -ne 2 ] ;then echo "Usage : $0 [source dir] [dest dir]" exit 1 fi if [ ! -d $1 ] ;then echo "\"$1\" must be a directory, please check." exit 1 fi if [ ! -w $2 ] ;then if [ ! -a $2 ] ;then echo -n "\"$2\" does not exist, do you want to create it? [y/n] :" read ans while [ true ] ;do case "$ans" in y|Y|yes|YES) mkdir $2 if [ $? -ne 0 ] ;then echo "Write \"$2\" error" exit 1 fi break ;; n|N|no|NO) echo "Ok, don't creat directory, so this will done nothing." exit 0 ;; *) echo -n "Expect \"yes\" or \"no\", please answer [y/n] :" read ans esac done else echo "\"$2\" does not have write permission, please check." exit 1 fi else if [ ! -d $2 ] ;then echo "\"$2\" is not a directory, please check." exit 1 fi fi LISTFILE=`ls $2` if [ ! -z "$LISTFILE" ] ;then echo -n "There is some file in \"$2\", still process copy directory? [y/n] :" ans="" read ans while [ true ] ;do case "$ans" in y|Y|yes|YES) break ;; n|N|no|NO) echo "Ok, don't process, so this will done nothing." exit 0 ;; *) echo -n "Expect \"yes\" or \"no\", please answer [y/n] :" read ans esac done fi SOURCEPARDIR=`dirname $1` SOURCENAME=`basename $1` DESTPARDIR=`dirname $2` DESTNAME=`basename $2` CURRDIR=`pwd` echo "Copy in process..." cd $1 if [ $DESTPARDIR = "." ] ;then # Destination is relative reference find -print | cpio -pd $CURRDIR/$DESTNAME else # Destination is full reference find -print | cpio -pd $DESTPARDIR/$DESTNAME fi cd $CURRDIR echo "Copy directory complete." exit 0อธิบาย
if [ $# -ne 2 ] ;then
if [ ! -d $1 ] ;then
if [ ! -w $2 ] ;then
if [ ! -a $2 ] ;thenส่วน
$ copydir /home/user1 ./user2จะ
CURRDIR=`pwd` find -print | cpio -pd $CURRDIR/$DESTNAMEแต่
จะ
สำหรับ
ใน
fyesno "\"$2\" does not exist, do you want to create it? [y/n] :"
และ
fyesno "There is some file in \"$2\", still process copy directory? [y/n] :"
สำหรับ
#!/bin/sh
#--------------------------------------------------------
fyesno () {
echo -n $1
read ans
while [ true ] ;do
case "$ans" in
y|Y|yes|YES)
# 0 - on success (true in shell)
return 0 ;;
n|N|no|NO)
# 1 - on fail (false in shell)
return 1 ;;
*)
echo -n "Expect \"yes\" or \"no\", please answer [y/n] :"
read ans
esac
done
}
#-----------------------------------------------------------
if [ $# -ne 2 ] ;then
echo "Usage : $0 [source dir] [dest dir]"
exit 1
fi
if [ ! -d $1 ] ;then
echo "\"$1\" must be a directory, please check."
exit 1
fi
if [ ! -w $2 ] ;then
if [ ! -a $2 ] ;then
fyesno "\"$2\" does not exist, do you want to create it? [y/n] :"
if [ $? -eq 0 ] ;then
mkdir $2
if [ $? -ne 0 ] ;then
echo "Write \"$2\" error"
exit 1
fi
else
echo "Ok, don't creat directory, so this will done nothing."
exit 0
fi
else
echo "\"$2\" does not have write permission, please check."
exit 1
fi
else
if [ ! -d $2 ] ;then
echo "\"$2\" is not a directory, please check."
exit 1
fi
fi
LISTFILE=`ls $2`
if [ ! -z "$LISTFILE" ] ;then
fyesno "There is some file in \"$2\", still process copy directory? [y/n] :"
if [ $? -eq 1 ] ;then
echo "Ok, don't process, so this will done nothing."
exit 0
fi
fi
SOURCEPARDIR=`dirname $1`
SOURCENAME=`basename $1`
DESTPARDIR=`dirname $2`
DESTNAME=`basename $2`
CURRDIR=`pwd`
echo "Copy in process..."
cd $1
if [ $DESTPARDIR = "." ] ;then
# Destination is relative reference
find -print | cpio -pd $CURRDIR/$DESTNAME
else
# Destination is full reference
find -print | cpio -pd $DESTPARDIR/$DESTNAME
fi
cd $CURRDIR
echo "Copy directory complete."
exit 0
ใน
HTML developed by Kaiwal Development Team (kaiwal@geocities.com)