Rename file extension recursively

This is a simple bash script to rename all JPG file extensions to JPEG, it works recursively and takes subfolders also.

#!/bin/bash

function rename_extension
{
        #change all .jpg to .jpeg
        for file in $1/*.jpg; do
                mv $file $1/`basename $file .jpg`.jpeg;
                echo $file;
        done;

        # recurse directories
        for d in $1/*; do
                if test -d $d; then
                        rename_extension $d;
                fi;
        done;
}

dir=`pwd`;

rename_extension $dir;