Escape characters contained by bash variable in regex pattern

Posted by Skuja on Stack Overflow See other posts from Stack Overflow or by Skuja
Published on 2010-05-29T02:09:48Z Indexed on 2010/05/29 2:12 UTC
Read the original article Hit count: 443

Filed under:
|
|
|

In my bash script, i am trying to execute following Linux command:

sed -i "/$data_line/ d" $data_dir

$data_line is entered by user and it may conatain special characters that could brake regex. How can i escape all of the possible special characters in $data_line before i execute sed command?

© Stack Overflow or respective owner

Related posts about regex

Related posts about bash