Piping to ex from a script

Is anyone piping commands to ex from scripts?

I.E.

echo '%s/change this/to that/\nwq' | ex file.name

I've been using it for years with AIX, Solaris, SGI, with variations ksh and Mandriva and others with pdksh. I've just started using CentOS with ksh and it no longer works. I've tried single quotes double, etc... I've also tried using other shells to no avail. zsh does work, but I don't know how compatible the rest of my scripting would be with it.

I know that Mandriva uses pdksh and CentOS is using AT&T korn shell. I know that there are differences between the two, such as returning variables from subroutines, etc...

I use this type of file manipulation a lot. It's very convenient to be able to change a file without having to create an intermediate file like you would with sed.

Any ideas on why something this simple won't work with AT&T's ksh, or what I need to do to get it working? Or, should I just give in and switch to zsh for the scripts that use ex?

Thanks in Advance.

printf '%cs/change this/to that/\nwq' '%' | ex file.name

I guess I was looking so hard at the format of the echo statement, I didn't see that it could have been the problem!!! As I read that I heard a very loud "POP" I think it might of been my head coming out of my tail... :eek:

But Like I always say... "I'd rather have a bottle in front of me than a frontal lobotomy!"

Thanks a bunch.

P.S. The printf didn't work. echo -e did.