Shell Scripting Problem - Invalid Back Reference

Here is the question...

Create a new script, sub2, taking three parameters...

1.) the string to be replaced
2.) the string with which to replace it
3.) the name of the file in which to make the substitution

...that treats the string to be replaced as plain text instead of as a regular expression.

Hint 1: Try to get the string to be replaced into a shell variable (e.g., $target). Then use a sed command to rewrite any special regular expression characters in that string so that they get treated as text, storing the result in a second shell variable (e.g., $newTarget). Then issue the actual command to perform the substitutions on the file.

Hint 2: For technical reasons, this task is probably easier accomplished in /bin/sh than in /bin/csh. If you insist upon using csh to run your script, you might need to solve this by writing your sed commands into a separate temparary file and using the -f option of sed to run commands from that file.

This is what I've got so far, but for some reason I keep getting the same error message...

#!/bin/bash
# Script to substitute text

# 0.00 17Jul2012 AI Copy sub1.sh
# 0.01 17Jul2012 AI Convert target to plain text
# 0.02 18Jul2012 AI basename $3

# Usage:
# ./sub2.sh string replace file

echo $1                # Echo options
echo $2
echo $3

plain=`echo "$1" | sed 's/./\\\&/g'`    # Convert target to plain text

basetmp=`basename $3`
tmpfile="/tmp/$basetmp.$$"        # Unique temporary file
sed "s/$plain/$2/g" "$3" > "$tmpfile"    # Edit
mv "$tmpfile" "$3"        # Recover edits

and the error message I get is...

sed: -e expression #1, char 8: Invalid back reference

This is clearly classwork. Please review our policy on homework, and repost in the homework forum. That requires you to answer questions about the course and school.