Activity - shell script
Read backup.sh.
Let’s modify the backup scrpt. For each file, first check whether a backup has been made. If there is no backup for the file, then create a backup for the file and add ‘.bak’ to the original file name. If there is a backup, then run the diff
command (see man diff
) to compare the file and its backup. If the file and its backup are the same, take no action. If the file and its backup are different, make a new back.
Make a copy of the script for yourself,
cp /thayerfs/courses/22fall/cosc050/workspace/activities/day4/backup.sh .
or, to work on your laptop,
scp netid@plank.thayer.dartmouth.edu:/thayerfs/courses/22fall/cosc050/workspace/activities/day4/backup.sh .
Practicing defensive programming, we should make our script able to handle various input arguments gracefully. Thus, our script should check each given file name and see if the file exists first before checking its backup.