1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#!/bin/bash
if [ -z "$2" ] ; then
echo "Usage: mv_if_diff source target"
echo "Moves source to target."
echo "If target does not differ from source, target is kept untouched."
echo "If target does not exist, source is always moved to target."
echo "source always gets removed."
exit 1
fi
if [ -f "$2" ]; then
DIFF=`diff $1 $2 | wc -l`
if [ $DIFF = 0 ] ; then
echo "$2 did not change."
rm $1
else
echo "$2 updated."
mv $1 $2
fi
else
echo "$2 created."
mv $1 $2
fi
|