因此,我需要在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