#!/bin/bash # # backup-solution.sh - make a backup copy of all the .c files in current directory # # usage: backup-solution.sh # (no arguments) # # input: none # output: a line of confirmation for each file backed up # # Tim Pierson, Fall 2022 for i in *.c do echo "backing up $i" # check if backup alredy exits if [ -f "$i.bak" ]; then echo -e "\tback up already exists" # back up exists, see if back up same as .c diff "$i" "$i.bak" &>/dev/null #send diff output to /dev/null if [ "$?" -ne 0 ]; then #not the same, make new back up echo -e "\tback up doesn't match .c, making new .bak file" cp "$i" "$i.bak" else echo -e "\tback up matches .c, making no changes" fi else echo -e "\tback up does not exist, making new .bak file" cp "$i" "$i.bak" fi done exit 0