I think I see the error - it appears to be in the function declaration.
You have parens there, and I think that's causing the error.
"Declaring a function is just a matter of writing function my_func {
my_code }.
"
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-8.html
Missing from your script was the the interpreter path (not
sure if it was left off when you copy/pasted or if it it's
missing from your actual bash script.
On some systems this line looks like
#!/usr/local/bin/bash
or
#!/usr/bin/bash
but for portability, I usually use
#!/bin/sh
and because of systematic symlinks, it "finds" the bash
interpreter path wherever it may happen to be.