Replace a string in shell script using a variable

后端 未结 10 932
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 05:18

I am using the below code for replacing a string inside a shell script.

echo $LINE | sed -e \'s/12345678/\"$replace\"/g\'

but it\'s getting

10条回答
  •  孤街浪徒
    2020-11-22 05:34

    echo $LINE | sed -e 's/12345678/'$replace'/g'
    

    you can still use single quotes, but you have to "open" them when you want the variable expanded at the right place. otherwise the string is taken "literally" (as @paxdiablo correctly stated, his answer is correct as well)

提交回复
热议问题