#!/bin/bash
##
## util-linux rename(1) clone
## Copyright (c) 2009 SATOH Fumiyasu @ OSS Technology Corp.
##               <http://www.osstech.co.jp>
##
## License: GNU General Public License version 2 or later
## Date: 2009-01-05, since 2009-01-05
##

set -u

if [ $# -lt 2 ]; then
  echo "Usage: $0 PATTERN REPLACEMENT FILENAME [...]"
  exit 1
fi
from_p="$1"; shift
to_p="$1"; shift

for from in ${1+"$@"}; do
  to="${from/$from_p/$to_p}"
  [ x"$from" = x"$to" ] && continue
  mv "$from" "$to" || exit 1
done

exit 0

