Bash pattern capture in script

I am using a Bash script to read line by line from a text file that has special characters (regular expression). When I use echo "${SOME_VAR}" , it does not display the text as it is .

I am familiar with the Prevent * for extension in Bash script .

How can I display and use text as is?

UPDATE A text file (TSV) contains tuples similar to (the last entry is a psql query)

 bathroom bathroom select name from photos where name ~* '\mbathroom((s)?|(''s)?)\M'; 

I read CSV as follows:

 tail -n+2 text.file | while IFS=$'\t' read xyz do echo "${z}" done 

which gives way

 select name from photos where name ~* 'mbathroom((s)?|(''s)?)M'); 

note that "\" is missing

+4
source share
1 answer

Try using the -r flag with read :

 tail -n+2 text.file | while IFS=$'\t' read -rxyz do echo "${z}" done 

On the read man page:

-r Do not handle backslashes in any special way. Consider each backslash as part of the input string.

+3
source

All Articles