Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a bash script variable with sed [duplicate]

I execute the following bash script:

#!/bin/bash
version=$1
echo $version
sed 's/\${version.number}/$version/' template.txt > readme.txt

I'm expecting to replace all instances of ${version.number} with the contents of the variable "version". Instead the literal text $version is being inserted.

What do I need to do to make sed use the current value of $version instead?

like image 519
Steve McLeod Avatar asked Jul 08 '10 13:07

Steve McLeod


1 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.

like image 58
Matthew Flaschen Avatar answered Oct 02 '22 15:10

Matthew Flaschen