Hi,
I've a file having some regular expressions.
e.g. cat regex.txt
[\t\n]
abc.*pqr

If I write a small bash script as below,

while read line
do
echo -E "$line"
done < regex.txt

even with -E switch passed to echo the output is
[tn]
abc.*pqr

So the backslashes have vanished in the first regular expression.
Is there a way to retain all backslashed escape sequences
while reading a file using the while loop ?

Thanks,
Mahendra

while IFS= read -r;do 
  printf '%s\n' "$REPLY"
done<regex.txt
while IFS= read -r;do 
  printf '%s\n' "$REPLY"
done<regex.txt

Thanks Radoulov. It's now reading \ literally without interpreting it.

Why's it work?

Matter inside double quotes (") is interpreted/evaluated by the shell. Matter inside single quotes (') is not.

It's a handy tool, but can cause some stubbed toes along the way. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.