Shell - sed not replacing variables

Hi,

Im using this sed command in order to replace a line in the hosts file but as I run the script it looks like its not replacing the variables per their value...

sed -i 's/${host_db}/${new_db}   db-01/' /etc/hosts

Running using sh -x I get this:
+ new_db=10.216.193.68
+ host_db='12.18.1.61   db-01'
+ sed -i 's/${host_db}/${new_db}   db-01/' /etc/hosts


Anything I might be missing?

Tks,
Joao
joaotellesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
sed -i 's/'${host_db}'/'${new_db}'   db-01/' /etc/hosts
0
woolmilkporcCommented:
Or

sed -i "s/${host_db}/${new_db}   db-01/" /etc/hosts

Background:

The shell does not resolve variables enclosed by single quotes, so you must either take them out of the quotes (first solution) or use double quotes instead (second solution) - if there is nothing which shall be protected from the shell intentionally, that is.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
joaotellesAuthor Commented:
Tks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.