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.