Expand variables in sed

前端 未结 2 1592
渐次进展
渐次进展 2020-12-07 00:38

I need use sed into bash script, for add lines after any line numer of script with some pair of values (below work)

sed -i.bak \'14i\\some_text=some_text\' f         


        
2条回答
  •  一整个雨季
    2020-12-07 01:35

    Just use double quotes instead of single quotes. You'll also need to use {} to delimit the number_line variable correctly and escape the \, too.

    sed -i.bak "${number_line}i\\$var1=$var2" $var3
    

    I'd personally prefer to see all of the variables use the {}, ending up with something like:

    sed -i.bak "${number_line}i\\${var1}=${var2}" ${var3}
    

提交回复
热议问题