SED script to backslash special characters

I have a shell script that I have written to be a kind of to-do/notepad that's quickly executable from the command line. However, special characters tend to break it pretty well.

Ie: "notes -a This is an entry." works fine.
"notes -a This is (my) entry." will toss back a bash syntax error on the (.

I was curious if there is an easier way of correcting special characters than writing a sed script to backslash them automatically. I realize that I could do it manually, but it's supposed to be a quick-and-easy program.

Current plan is to write a sed script to backslash certain characters, but I'm open to suggestions.

I've usually gone with awk

echo 'This$ has *special char()'  | awk '{gsub( /[(*|`$)]/, "\\\\&"); print $0}'

Not quite sure if this is what you're looking for, but recent bash versions support the non standard format specification q with printf:

bash-4.1.5(1)[t]$ cat infile 
notes -a This is (my) entry.
This$ has *special char()
bash-4.1.5(1)[t]$ while IFS= read -r;do printf '%q\n' "$REPLY";done<infile
notes\ -a\ This\ is\ \(my\)\ entry.
This\$\ has\ \*special\ char\(\)

Otherwise you can use Perl:

bash-4.1.5(1)[t]$ perl  '-ple$_=quotemeta' infile 
notes\ \-a\ This\ is\ \(my\)\ entry\.
This\$\ has\ \*special\ char\(\)

using quotemeta in perl is brilliant choice.

You need to quote the parameter on the command line to stop shell interpreting the special characters. The error message from the () is before your script runs.
The double quotes in this example are important.

notes -a "This is (my) entry."

Thank you for all of the responses. Amusingly enough, quoting the input on the command line seems to solve the problems I was having. I don't know if I can alias something to auto-quote the entries, or if I will have to do it manually.

I did walk through all of these, radoulov's perl script was really neat, I'm going to keep that quotemeta function in mind for other projects. I couldn't get jim mcnamara's awk working, however.