Skip to content

Instantly share code, notes, and snippets.

@aeris
Created August 8, 2012 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeris/3293610 to your computer and use it in GitHub Desktop.
Save aeris/3293610 to your computer and use it in GitHub Desktop.
Backup utility
#!/bin/bash
backup() {
mv "${1}" "${1}.bak"
}
restore() {
mv "${1}" "${1/%\.bak/}"
}
handle() {
EXT=${1##*.}
case "${EXT}" in
bak)
restore "${1}"
;;
*)
if [ -e "${1}.bak" ]; then
restore "${1}.bak"
else
backup "${1}"
fi
;;
esac
}
case "${1}" in
-a)
for FILE in *.bak; do
restore "${FILE}"
done
;;
*)
for FILE in $*; do
handle "${FILE}"
done
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment