#!/bin/bash
if [ $# -ne 2 ]; then
    echo "Usage: $0 <value>"
    exit 1
fi
source_dir=$1
target_dir=$2
create_copy(){
    if [ ! -d "$source_dir" ]; then
    echo "源目录不存在"
    exit 1
fi

if [ ! -d "$target_dir" ]; then
    mkdir -p "$target_dir"
    if [ $? -ne 0 ]; then
        echo "创建目标目录失败"
        exit 1
    fi
fi

cp -r "$source_dir"/* "$target_dir"
if [ $? -ne 0 ]; then
    echo "拷贝文件失败"
    exit 1
fi

rm -rf "$source_dir"
if [ $? -ne 0 ]; then
    echo "删除源目录失败"
    exit 1
fi

ln -s "$target_dir" "$source_dir"
if [ $? -ne 0 ]; then
    echo "建立链接失败"
    exit 1
fi

}
create_copy
