title: Executing different commands with separate arguments
body: <p>Say that I want to make a script that extracts all tar.gz and tar.bz2 files that are listed as arguments. What I've done so far is something like: </p>
  
  <pre><code>if [[ $@ =~ .*"tar.gz".* ]] || [[ $@ =~ .*"tar.bz2".* ]]; then
   for i in $@ =~ .*"tar.gz".*; do
    tar -xvzf "$i"
   done
   for p in $@ =~ .*"tar.bz2".*; do
    tar -xvjf "$p"
   done
  else
   echo "tar.gz or tar.bz2 files required."
  fi 
  </code></pre>
  
  <p>The first line is successful at evaluating whether or not a tar.gz or tar.bz2 file exist, but my problem is the rest. The variables aren't set properly, and the script ends up trying to extract each variable listed with both extraction commands. How can I separate arguments that end with tar.gz and tar.bz2 to perform separate extractions?</p>