#!/usr/bin/env bash

# Usage:
# ./bak [-v] [filename] [filename] ...

if [ "$#" -eq 0 ]; then
  echo "Usage: $0 [filename] [filename]..."
  exit 1
fi

if [ "$1" == "-v" ] || [ "$1" == "--version" ]; then
  echo "what version? this is a tiny little script, sir"
  exit 0
fi

if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
  echo "Usage: $0 [filename] [filename]..."
  exit 0
fi

for file in "$@"; do
  if [ -f "$file" ]; then
    cp "$file" "$file.bak"
    echo "Backed up $file to $file.bak"
  else
    echo "file '$file' does not exist"
  fi
done
