Hey thanks for that, it worked
but there's another problem now...we are trying now to create a second script called "subst2" that does the exact same thing as the "subst1" but leaves the file completely unchanged (and does not create the .bak file) if the string being replaced is nowhere in the file.
Also, the subst2 is supposed to be generalized so that it will produce a new script called "subst" that will apply a substitution to any amount of files...for example:
PHP Code:
~/test/subst happy cow myFile1.txt myFile2.txt myFile3.txt
I figured that this might work:
PHP Code:
#!/bin/sh
if [ -z "$3" ] ; then
echo expect string1, string2, file
exit 1
fi
if [ -e "$3" ] ; then
mv "$3" "$3.bak"
sed "s/$1/$2/g" "$3.bak" > "$3"
else
echo $3 not found
exit 1
fi
But it didn't...I think that -z is a problem...but really frustrated that I can't find why...my book doesn't help much
