bak (416B) [raw]
1 #!/bin/sh 2 # bak -- move a file to file.bak (or back) 3 set -e 4 die() { 5 echo "$*" 1>&2 6 exit 1 7 } 8 9 [ -z "$1" ] && die "usage: bak FILE" 10 11 BAK="$1.bak" 12 if [ -e "$BAK" ] && [ -e "$1" ]; then 13 die "$1 and $BAK exist, unable to bak or unbak" 14 elif [ -e "$BAK" ]; then 15 mv "$BAK" "$1" 16 echo "$BAK -> $1" 17 elif [ -e "$1" ]; then 18 mv "$1" "$BAK" 19 echo "$1 -> $BAK" 20 else 21 die "Neither $1 nor $BAK exist, unable to bak or unbak" 22 fi