How to use a bash script variable with sed

<>

This question already has an answer here:

Answers


sed "s/\${version.number}/$version/" template.txt > readme.txt

Only double quotes do dollar-sign replacement. That also means single quotes don't require the dollar sign to be escaped.


You could also simply unquote the variables

sed 's/'${version.number}'/'$version'/' template.txt > readme.txt

It's a bit old, but it might still be helpful... For me it worked using a double escape as Philip said (and escaping parenthesis, if you use them...):

#!/bin/bash
LIVE_DB_NAME='wordpress';
STAGING='staging';
sed -r "s/define\('DB_NAME', '[a-zA-Z0-9]+'\);/define('DB_NAME', '\\${LIVE_DB_NAME}');/" ${STAGING}/wp-config.php >tmp1;

Need Your Help

Creating a condition on a resource based on key-pair name

amazon-web-services amazon-iam

I am attempting to limit ability to modify instances based on the use of key-pair name on an instance.

How to get unique key from android application dynamically that only my app knows about ?

android encryption

I have gone through similar questions on stackoverflow and other sites but could not find satisfactory answer.So I am asking new question with detailed requirements.