numargs=$#
filelist=
copylist=
while [ "$#" -gt 1 ]
do
filelist="$filelist $1"
shift
done
to="$1"
if [ "$numargs" -lt 2 -o "$numargs" -gt -2 -a !-d "$to" ]
then echo "usage wrong"
exit 1
fi
for from in $filelist
do
if [ -d "$to" ]
then tofile="$to/$(basename $from)"
else
tofile="$to"
fi
if [ -e "$tofile" ]
then
echo "$tofile already exists overwrite?"
read answer
if [ $answer=yes ]
then
copylist="$copylist $from"
fi
else
copylist="$copylist $from"
fi
done
if [ -n "$copylist" ]
then
cp $copylist $to
fi
运行错误检测
$copp aa #copp为文件名称
提示 mycp3[10]: [: argument expected
应该echo "usage wrong"然后退出阿
另外 谁能解释一下exit 0 根exit 1 有什么区别呢 退出不同的层次么?
仔细比较50次
!-d
! -d
阅读(1199) | 评论(0) | 转发(0) |