dotfiles/.local/bin/scripts/bak

13 lines
246 B
Plaintext
Raw Normal View History

#!/bin/sh
2021-07-04 16:20:36 +00:00
suffix="${2:-bak}"
2021-07-04 19:56:12 +00:00
orig="${1%%.$suffix}"
2021-09-20 09:14:34 +00:00
smv () {
test -w "$1" && mv -v "$@" || sudo mv -v "$@"
}
2021-07-04 19:56:12 +00:00
if test -e "$orig.$suffix"
then
2021-09-20 09:14:34 +00:00
test -e "$orig" && smv "$orig" /tmp
smv -n "$orig.$suffix" "$orig"
else smv -n "$1" "$1.$suffix"
2021-07-04 19:56:12 +00:00
fi