Having trouble writing a basic shell program

Hello. I'm trying to write a shell script that will take files that have .tar, .tar.gz, .tar.Z, .gz, .Z and .zip file extensions and uncompress and unarchive them. The script should be able to take multiple arguments. So far I can write a script using the case command that will do this but it will only take one argument. Also, I need to make it so that if it does not have one of those file extensions then it will return an error message. I think I need to use either a for or while loop and shift to do this but I'm just not getting it for some reason. Any ideas? I appreciate greatly any help anyone might have on this.

Btw,.. for the record, here is what I have so far:

#!/bin/bash
# Program: uncomp

filelist=

while [ "$#" -ge 1 ]
do
filelist="$filelist $1"
shift
done

for var in $filelist
do
tar -xvf "$var"
done

This might get you started....

$ cat bashfiles
#! /usr/local/bin/bash

for arg ; do
        case $arg in
        *.tar)
                echo $arg is a tar file
                ;;
        *.Z)
                echo $arg is a compressed file
                ;;
        *.gz)
                echo $arg is a gzipped file
                ;;
        *)
                echo $arg is an unsupported file type
                ;;
        esac
done
exit 0
$ ./bashfiles a b c d e f g h i j k  a.tar b.gz c.Z
a is an unsupported file type
b is an unsupported file type
c is an unsupported file type
d is an unsupported file type
e is an unsupported file type
f is an unsupported file type
g is an unsupported file type
h is an unsupported file type
i is an unsupported file type
j is an unsupported file type
k is an unsupported file type
a.tar is a tar file
b.gz is a gzipped file
c.Z is a compressed file
$

Thanks man! That is awesome! Thank you so much. :slight_smile: