bash - Shell script - sed doesn't work -


i have: test.txt:

version-1 version-1 

ori.sh:

old="version-1" new="version-2" sed -i .bak 's/${old}/${new}/g' test.txt 

when running ori.sh, nothing happens. expect test.txt like:

test.txt*:

version-2 version-2 

any ideas?

single quotes problem. bash (or other shells) don't expand variables in single quotes.

use sed command double quotes shell can expand variables:

sed -i.bak "s/${old}/${new}/g" test.txt 

Comments