I am trying to keep the return of a sed substitution in a variable:
-
D=domain.com echo $D | sed 's/\./\\./g'Correctly returns: domain\.com
-
D1=`echo $D | sed 's/\./\\./g'` echo $D1Returns: domain.com
What am I doing wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Think of shells rescanning the line each time it is executed. Thus echo $D1, which has the escapes in it, have the escapes applied to the value as the line is parsed, before echo sees it. The solution is yet more escapes.
Getting the escapes correct on nested shell statements can make you live in interesting times.