I suggest you take a look at the Advanced Bash Scripting Guide I linked to in my first post, paying particular attention to Part 2, Chapter 7.
www.linuxquestions.org