Please see these simple commands:
$ echo $tmp
UY\U[_
$ echo "a" | sed "s|a|${tmp}|g"
UY[_
The \U is eaten. Other backslashes won’t survive either.
How can I make the above command work as expected?
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.
If it’s only backslash that is “eaten” by sed and escaping just that is enough, then try:
Confusing enough for you?
\\represents a single \ since it needs to be escaped in the shell too.The inital
//is similar to thegmodifier ins/foo/bar/g, if you only want the first occurring pattern to be replaced, skip it.The docs about
${parameter/pattern/string}is available here: http://www.gnu.org/s/bash/manual/bash.html#Shell-Parameter-ExpansionEdit: Depending on what you want to do, you might be better of not using sed for this actually.