dotfiles/.local/bin/scripts/bak

18 lines
295 B
Bash
Executable File

#!/bin/sh
suffix="${2:-bak}"
orig="${1%%.$suffix}"
smv () {
eval source=\$$(($#-1))
if test -w "$source"
then mv -v "$@"
else sudo mv -v "$@"
fi
}
if test -e "$orig.$suffix"
then
test -e "$orig" && smv "$orig" /tmp
smv -n "$orig.$suffix" "$orig"
else
smv -n "$1" "$1.$suffix"
fi