1 Star 0 Fork 0

杨谨徽/代码托管

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
myrcp.sh 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
杨谨徽 提交于 2023-09-23 16:40 +08:00 . add myrcp.sh.
#! /bin/bash
cpf2f()
{
if [ ! -e $1 ]; then
echo no such source file $1
return 1
fi
if [ $1 -ef $2 ]; then
echo "never copy a file to itself"
return 1
fi
if [ -L $1 ]; then
echo "copying symlink $1"
link=$(readlink $1)
ln -s $link $2
return 0
fi
echo "copying $1 to $2"
cp $1 $2 2> /dev/null
}
cpf2d()
{
newfile=$2/$(basename $1)
cpf2f $1 $newfile
}
cpd2d()
{
src=$1
dest=$2
if [ ! -d $dest ]; then
echo "Destination $dest is not a directory."
return 1
fi
newdir=$dest/$(basename $src)
mkdir -p $newdir
for file in $src/*; do
if [ -f $file ]; then
cpf2f $file $newdir/$(basename $file)
elif [ -d $file ]; then
cpd2d $file $newdir
fi
done
}
#******************entry point of myrcp******************
#case analysis;
#for each f1 to fn-1 call cpf2f() or cpf2d() or cpd2d()
myrcp()
{
if [ $# -lt 2 ]; then
echo "use myrcp f1 f2 ... fn"
return 1
fi
num_args=$#
dest=${!num_args}
if [ ! -d $dest ]; then
if [ $# -eq 2 ]; then
dest=$2
else
echo "Destination $dest does not exist."
return 1
fi
fi
for ((i=1; i<num_args;i++)); do
src=${!i}
if [ ! -e $src ]; then
echo "no such source file $src"
continue
fi
if [ -d $dest ]; then
if [ -d $src ]; then
cpd2d $src $dest
else
cpf2d $src $dest
fi
else
cpf2f $src $dest
fi
done
}
myrcp $@
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/SHIBATORI/code-hosting.git
git@gitee.com:SHIBATORI/code-hosting.git
SHIBATORI
code-hosting
代码托管
master

搜索帮助