how to use env variables within ed

i have a file that i need to edit and replace a single value with another. so i have two variables, $oldvalue and $newvalue but below doesn't work:

ed file.txt << EOF
,s/$oldversion/$newversion/g
wq
EOF

i presume it's the $ that is the issue since it's actually special to ed. any suggestions? thanx in advance.

What characters are special to ed doesn't matter. The shell always substitutes before you run a program, the program shouldn't know or care.

When in doubt, substitute cat to check the pattern:

$ oldversion=32
$ newversion=64
$ cat <<EOF
,s/$oldversion/$newversion/g
wq
EOF
,s/32/64/g
wq

Seems okay to me, but yours may be slightly different, maybe your vars aren't what you thought they were, so try it :slight_smile: