#!/bin/bash # Test command line arguments if [ $# != 2 ]; then echo "usage: $0 [file1] [file2]" exit 1 fi FILE1=$1 FILE2=$2 TMPF="$FILE1.tmp" echo "Checking files..." if [ ! -f "$FILE1" ]; then echo "error: $FILE1 does not exist!" exit 1 fi if [ ! -f "$FILE2" ]; then echo "error: $FILE2 does not exist!" exit 1 fi if [ -f "$TMPF" ]; then echo "error: $TMPF already exists!" exit 1 fi echo "Copying $FILE1 to $TMPF..." cp "$FILE1" "$TMPF" if [ ! -f "$TMPF" ]; then echo "Failed to create temporary file $TMPF" exit 1 fi echo "Copying $FILE2 to $FILE1..." cp "$FILE2" "$FILE1" echo "Copying $TMPF to $FILE2..." cp "$TMPF" "$FILE2" echo "Deleting $TMPF..." rm "$TMPF"