title: Bash shell script to glob files in several directories, add to an archive and remove original file
body: <p>I am trying to write a bash script that does the following:</p>
  
  <ol>
  <li>Enumerates through list of files in a directory, that match a specified pattern</li>
  <li>Creates a tar file containing the matching files</li>
  <li>Removes (i.e. deletes) the matched files from their source directories</li>
  </ol>
  
  <p>To keep things simple, I intend to use a hard coded list of directories and file patterns</p>
  
  <p>This is what I have come up with so far:</p>
  
  <pre><code>#!/bin/bash
  
  filenames[0]='/home/user1/*.foo'
  filenames[1]='/some/otherpath/*.fbar'
  
  for f in ${filenames[@]}
     do
        echo "$f"
  done
  </code></pre>
  
  <p>However, I am unusure on how to proceed from this point onward. Specifically, I need help on:</p>
  
  <ol>
  <li>How to glob the files matching the pattern $f</li>
  <li>How to add the ENTIRE list of matching files (i.e. from all directories) to a tar file in one go</li>
  </ol>
  
  <p>Regarding deleting the files, I am thinking of simply iterating through the ENTIRE list obtained in step 2 above, and 'rm' the actual file - is there a better/quicker/more elegant way?</p>
  
  <p>PS:</p>
  
  <p>I am running this on Ubuntu 10.0.4 LTS</p>