#!/bin/sh

if [ $# != 2 ] ; then
  echo "usage: mulmv <truncated file name> <truncated destination file name>"
  echo "moves all files matching the truncated name to a new name"
  exit 1
fi

# make sure there are source files
shopt -s nullglob           # so $1* expands to null string if no files exist
files=$1*
if [ -z "$files" ] ; then
  echo "mulmv: found no files starting $1"
  exit 1
fi

# make sure destination file names don't exist
for i in $files ; do
  if [ -a $2${i:${#1}} ] ; then
    echo "mulmv: destination file $2${i:${#1}} exists"
    exit 1
  fi 
done

# do it
for i in $files ; do
  mv -i $i $2${i:${#1}}         # -i shouldn't be necessary, just in case...
done

exit 0

