Sed replace variable in double quotes

后端 未结 3 1182
日久生厌
日久生厌 2020-12-19 07:59

I\'ve created a bash script that takes a parameter. I want to pass that parameter to sed to replace an existing string with another which is composed of the variable:

<
相关标签:
3条回答
  • 2020-12-19 08:27

    Change your code like his,

    sed -i -e 's/name="master"/name="'"$variable"'"/g' test
    
    0 讨论(0)
  • 2020-12-19 08:33

    just do like this:

    var=apple
    sed -i "s/pineapple/$"
    
    0 讨论(0)
  • 2020-12-19 08:40

    Variable expansion does not happen within single quotes. Do it in double quotes:

    sed -i -e 's/name="master"/name="'"$variable"'"/g' test
    
    0 讨论(0)
提交回复
热议问题