Write a script copy_backup.sh that prompts the user a source folder and a destin
ID: 3838480 • Letter: W
Question
Write a script copy_backup.sh that prompts the user a source folder and a destination folder and then copies recursively the source folder into the destination folder while preserving the nesting hierarchy of the source folder. Your script must validate the following two conditions before you create a duplicate copy of the source folder into the destination folder: 1) the source folder must exit, and 2) the destination folder does not exit. In addition, your script must seek at least a confirmation before creating a copy backup of the source folder in the destination folder.
Explanation / Answer
#!/bin/bash
read -p "Enter Source Folder : " src_name
read -p "Enter Destibation Folder : " dest_name
if [ ! -d "$src_name" ]; then
echo "Source folder does not exist"
return;
fi
if [ ! -d "$dest_name" ]; then
echo "Dest folder exists"
return;
fi
read -p "Ready to copy(yes/no): " confirm
if [ "$conirm" == "yes" ]; then
cp -R $src_name $dest_name
fi
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.