backup.sh (524B)
1 #!/bin/sh 2 # backup 3 # description: cp $@ -> $@.bak 4 # e.g.$ backup ~/.bashrc ~/.vimrc 5 6 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then 7 echo "Usage: 'backup [OPTIONS] FILEPATHS...'" 8 echo "" 9 echo "copy all listed files (in FILEPATHS...) to \$filename.bak" 10 echo "" 11 echo "OPTIONS (must be provided before FILEPATHS...)" 12 echo " -m move files instead of copying them, removing the original" 13 exit 14 fi 15 16 alias backup='cp' 17 if [ "$1" = "-m" ]; then shift; alias backup='mv'; fi 18 for f in "${@}"; do backup "$f" "$f.bak"; done