sh: how to echo line without escape processing

I'm writing a shell script which processes a text file line by line and compares each line to string arguments passed down from the command line. Actually it is trying to solve the old problem of, if you have false hits in Procmail, how to you figure out which pattern is causing the problem?

The core of the script is something like this:
Code:
sed -n -e ...pattern to pull RE's from Procmail |   # pipe each Procmail RE into a while loop \
  while read line
  do
       echo "$*" | if grep -q "$line"
        then
                echo "HIT: $line"
       fi
  done

The script basically works, and I found the offending Procmail pattern. But I observed that the script is not quite right as
the construct "$line" used several times is doing escape processing and will remove backslashes, etc. How do I get
"$line" to not do any escape processing but keep the incoming line of text totally intact and unaltered?

edit: hmmm... on further examination, it may be the read line command instead that is discarding backslashes...
How do I do a read without escape processing?

it looks like read in some shells has a -r option which probably does the job...
 
gpatrick said:
My shell scripting is almost entirely written in ksh. This may be what you want:

print -r "Prints in raw mode. The escape conventions of the echo command are ignored."

I assume you mean that with something like \target, the \t is being translated to a tab; and you want "\target" and not "[tab]arget".
Code:
$ print -r -- $line
yes, but as it turns out, the problem is not with the "echo" but "read", so "read -r" solves the problem.
 
Back
Top