#!/bin/bash filename=$1 date=`date +%Y%m%d` usage () { echo "Usage: `basename $0` filename" } if [ -z "$filename" -a ! -f "$filename" ]; then usage exit 1 fi rev=0 backup="$filename.$date.$rev" while [ -f $backup ]; do let rev+=1 backup="$filename.$date.$rev" done cp $filename $backup exit $?