dotfiles/.local/bin/scripts/bak

13 lines
246 B
Bash
Executable File

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