Bash shell script to glob files in several directories, add to an archive and remove original file
I am trying to write a bash script that does the following:

1. Enumerates through list of files in a directory, that match a specified pattern
2. Creates a tar file containing the matching files
3. Removes (i.e. deletes) the matched files from their source directories

To keep things simple, I intend to use a hard coded list of directories and file patterns

This is what I have come up with so far:

    #!/bin/bash
    
    filenames[0]='/home/user1/*.foo'
    filenames[1]='/some/otherpath/*.fbar'
    
    for f in ${filenames[@]}
       do
          echo "$f"
    done


However, I am unusure on how to proceed from this point onward. Specifically, I need help on:

1. How to glob the files matching the pattern $f
2. How to add the ENTIRE list of matching files (i.e. from all directories) to a tar file in one go


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?


PS:

I am running this on Ubuntu 10.0.4 LTS
Bash shell script to glob files in several directories, add to an archive and remove original file
===

I am trying to write a bash script that does the following:

1. Enumerates through list of files in a directory, that match a specified pattern
2. Creates a tar file containing the matching files
3. Removes (i.e. deletes) the matched files from their source directories

To keep things simple, I intend to use a hard coded list of directories and file patterns

This is what I have come up with so far:

    #!/bin/bash
    
    filenames[0]='/home/user1/*.foo'
    filenames[1]='/some/otherpath/*.fbar'
    
    for f in ${filenames[@]}
       do
          echo "$f"
    done


However, I am unusure on how to proceed from this point onward. Specifically, I need help on:

1. How to glob the files matching the pattern $f
2. How to add the ENTIRE list of matching files (i.e. from all directories) to a tar file in one go


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?


PS:

I am running this on Ubuntu 10.0.4 LTS