script compare files and backup

Im working on a shell script that uses three parameters, a string to replace, the string replacing, and a file name.

In this script it makes a back up file before the replacement occurs. However I want to be able to either search the file to see if it has the string and if it doesnt dont create a backup. Or do the substition and compare the two files. I am lost, I assume it would be easier to search the file for the string then go from there, but this is what I have.

#!/bin/csh

set old_pattern="$1"
set new_pattern="$2"
set file_name="$3"

mv $file_name $file_name.bak
sed -e "s/$old_pattern/$new_pattern/g" $file_name.bak > $file_name

old=$1
new=$2
file=$3
grep $1 $3 > /dev/null
if [ $? -eq 0 ];then
	cp $3 ${3}.bak
	sed "s/$1/$2/g" $3 > ${3}~
	mv ${3}~ ${3}
fi

thank you,is this using sh shell?

I cant get it to work, I assume I am using the wrong shell?

---------- Post updated at 01:53 AM ---------- Previous update was at 12:11 AM ----------

anyone have any ideas? still cant get it to work:(

---------- Post updated at 07:45 PM ---------- Previous update was at 01:53 AM ----------

bump, could anyone help?

summer_cherry's syntax is Korn shell, if that helps?

It's more helpful when you say how it doesn't work.

i get

grep:be: no such file or directory

How many "words" are you passing to the script?

Try quoting the arguments as you pass them in.

i.e.

myScript this will be five arguments
...
$1=this
$2=will
$3=be
($4 and $5 are never used
 
 
Instead:
myScript "this will" "be three" arguments
...
$1="this will"
$2="be three"
$3=arguments