Help Modify call to functions depending on file name

Hi,

I am creating a script that does gunzip/unzip/untar depending on the file extension.

I have created 3 functions in my script and call them in following order.
1) gunzip function
2) unzip function
3) untar function

I am using

FILENAME=${FILENAME%.*} 

to modify filename between functions.

If the file name I receive is "mdm_ind_usa.2031.fsacm.tar.zip.gz" this script works fine.

But it does not work if the file name is like this "mdm_ind_usa.2031.fsacm.zip.tar.gz" or any other order of zipping.
I would like to modify my call to 3 functions depending on the extension of the file name.

I could use below code. But this code I have to put it 6 times all to capture all permutations and combinations.

 
#----------------- Check for Tar File -------------# 
if `ls -ltr ${FILEDIR}/${FILENAME}| grep .tar$ > /dev/null 2>&1` then
call_untar # (untar function call)
elif `ls -ltr ${FILEDIR}/${FILENAME}| grep .zip$ > /dev/null 2>&1` then
call_unzip # (unzip function call)
elif `ls -ltr ${FILEDIR}/${FILENAME}| grep .gz$ > /dev/null 2>&1` then 
call_gunzip # (unzip function call)
else
echo "text file"
fi

Help is appreciated to modify my call to functions depending on the file name in a more efficient manner.

Try sth along this line:

fn="mdm_ind_usa.2031.fsacm.tar.zip.gz"
ext=${fn##*.}
case "$ext" in
   gz)   call_gunzip;;
  tar)   call_untar;;
  zip)   call_unzip;;
esac

and loop the case statement until all extensions are used up.

Need help with looping please.