How can I insert a variable containing a backslash in sed?

后端 未结 2 471
我在风中等你
我在风中等你 2021-01-27 01:22

Please see these simple commands:

$ echo $tmp
UY\\U[_
$ echo \"a\" | sed \"s|a|${tmp}|g\"
UY[_

The \\U is eaten. Other backslashes

2条回答
  •  春和景丽
    2021-01-27 01:49

    You could reparse $tmp itself through sed

    echo "a" | sed "s|a|$(echo ${tmp} | sed 's|\\|\\\\|g')|g"
    

提交回复
热议问题