#!/bin/bash# we have less than 3 arguments. Print the help text:if [ $#-lt3 ]; then
cat<<HELP
ren -- renames a number of files using sed regular expressions
USAGE: ren 'regexp''replacement' files
EXAMPLE: rename all *.HTM files in *.html:
ren 'HTM$''html' *.HTM
HELP
exit0fi
OLD="$1"
NEW="$2"# The shift command removes one argument from the list of# command line arguments.
shift
shift
# $* contains now all the files:for file in $*; doif [ -f"$file" ]; then
newfile=`echo"$file" | sed "s/${OLD}/${NEW}/g"`
if [ -f"$newfile" ]; thenecho"ERROR: $newfile exists already"elseecho"renaming $file to $newfile "
mv "$file""$newfile"fifidone