因此,我需要在bash中写一个脚本来备份目录的文件。目录(备份)文件的Bash脚本
脚本获取文件(备份文件列表)作为参数,最后一个参数必须是目标文件夹(目录)。如果目标文件夹不存在,则必须通过脚本创建。
我打算使用循环来移动参数列表(文件),但我不知道如何使用最后一个参数,并检查它是否存在。
脚本召唤:
./myScript.sh file1 file2 file3... fileN target_folder
感谢。 :)
我开始:
#!/bin/bash
#doing backup of files passed as list of arguments.
if [ "$#" lt "2" ]
then
echo usage: "./myScript.sh <list of arguments -files for backup.>"
exit
fi
for arg in "$#"
do
if #last argument exist as folder in directory, just copy all files in
else #make targer folder and copy all files in
done
它听起来像你改写'cp'? – Kent
是的...任务很简单。我需要使用cp来做到这一点.. – gyrfalcon