#!/bin/sh

bakrotate() {
  if [ -f $1 ]
  then
    if [ -f "$1.bak" ]
    then bakrotate "$1.bak"
    fi
    mv "$1" "$1.bak"
  fi
}

for file in $@
do
  bakrotate "$file.bak"
  cp $file $file.bak
done