Changing file extensions in one fell swoop

Suppose we have hundreds of files in a directory with the extension .cpp and we need to change all these files to have an extension .cc instead. The following script mvall does this if used as following.

mvall cpp cc

#!/bin/sh
# simple/mvall
prog=`basename $0`
case $# in
0|1) echo 'Usage:' $prog '<original extension> <new extension>'; exit 1;;
esac

for f in *.$1
do
  base=$(basename $f .$1)
  mv $f $base.$2
done

The for loop selects all files with the given extension. The basename command is used to extract the name of each file without the extension. Finally the mv command is used to change the name of the file to have the new extension.