I'm working on a bourne shell utility script that reads
a bourne shell script, modifies then outputs it.
Obviously, there're problems inherent in that process.
I've managed to avoid read's destruction of the input
when it encounters a backslash, but now I'm stuck at the
output. (Read on before you suggest an answer :-)
One criteria is that whatever command or utility I use
must work in plain, vanilla bourne shell and must be a
VERY common utility (sed, awk, etc.). Portability
across platforms is critical (Solaris, HP-UX, AIX,
Linux) and assuming that anything but the bare minimum
installation is in place would be trouble.
printf works great, but may not be available. So far,
my attempts to get awk to do the job have not been
pretty (I can't seem to get the quoting right to pass
the string as-is to awk). Here's an example line that
_ECHO='echo' ; [ "x`echo \"\n\"`" = 'x\n' ] && ECHO="echo -e"
As you can see, the presence of \n as well as single and
double quotes makes it tricky. All I want to do is output
it to a file as-is, but... (I can't process the line to
add backslashes since that usually involves echo-ing it
through sed or somesuch and echo would corrupt the line.)
Any suggestions? Tricks? I could include a small utility
with the script, one for each target platform, if I had
to as long as there were no legal restrictions on its
distribution (it wouldn't be part of our product, just
a necessary helper). -Wm