Error during Accessing Global variable inside function

emailid=myemail@xyz.com
taskName="DB-Backup"
starttime=`date`
email()
{
        subject="$taskName" ": " $* " at `date` "
        mutt -s "$subject" $emailid < /dev/null
}

email "Starting"
#do my stuff
email "Finished"

The above code gives following error
./dbbackup.sh: line 6: : : command not found
./dbbackup.sh: line 6: : : command not found

Basically the assignment of variable " subject="$taskName" ": " $* " at `date` " " causes the error because of using the $taskName in it. Because when i remove $taskName from it it gives no error. But this kind of assignment works outside the function.

I am relatively new to functions in shell and any help is appreciated.
Thanks
-Nitiraj

change the subject to

you need to escape the " (double quotes)

subject="$taskName\" \": \" $* \" at `date` "

Whatever variable you defined outside the function to be exported. Exprted variable can be used inside function

Eg :: export taskName

Try this...

subject="$taskName :  $*  at `date` "

--ahamed

Sorry forget last comment. Yeah, this is your problem. There is unwanted quote space between $*.

subject="$taskName" ": "$*" at `date` "

Whenever you are using $* and $@ it should be quoted properly.

Further to ahmed101, you also need a pair of escaped quotes on the mutt line.

        subject="$taskName :  $*  at `date` "
        echo mutt -s \""$subject"\" $emailid < /dev/null

@sanoop etc.
The original problem was that ":" (colon) is a Shell command and it was trying to execute ": " (colon with an argument of a space character).