#!/bin/bash # # backup-arg.sh - make copy for specified files # # usage: ./backup-args.sh [filename] ... # # input: list of file names # output: # # CS50, Spring 2022 ret=0 for i in "$@" do # check if a given file exists if [ ! -f "$i" ] then echo 1>&2 "file $i does not exist" ((ret+=1)) continue fi if [ -f "$i.bak" ] then diff "$i" "$i.bak" else echo "creating backup for $i..." cp "$i" "$i.bak" fi done exit $ret