Code:
#!/bin/bash
#
# Andrew <andrew@topdog.za.net>
# Quick dirty script to backup a file
# 03-02-2008
#
if [[ "$1" = "" || "$1" = "--help" ]]; then
echo " Usage: $0 <file to backup>"
echo ""
exit 1
fi
if [ ! -r $1 ]; then
echo "The file $1 does not exist"
echo ""
exit 1
fi
#work around for systems with cp -i alias
aliased=0
j=$(alias | grep cp &>/dev/null)
if [ "$?" = "0" ]; then
i=$(alias cp | grep '\-i' &>/dev/null)
if [ "$?" = "0" ]; then
aliased=1
unalias cp
fi
fi
# actual copy
cp -a $1 $1.bak
if [ $aliased = "1" ]; then
alias cp='cp -i'
fi