Lê Minh Quân
Lê Minh Quân

Reputation: 177

How to replace an input string to file?

I have a config file that need to replace DBpass and host ip when deploy

some code look like this: {DBPASS}@{ip}

I create a scripts file to replace them like this

echo "Host IP?"
read ip
sed -i 's/{ip}/$ip/g' abc.conf
echo "DB pass?"
read dbpass
sed -i 's/{DBPASS}/$dbpass/g' abc.conf

and it turn out to be like this in config file $dbpass@$ip

So how can I make the sed command in shellscripts replace the word I input before.

Upvotes: 0

Views: 24

Answers (1)

Kent
Kent

Reputation: 195039

change the single quotes ' into double quotes " in your sed commands, so that the shell variables can be expanded.

Upvotes: 2

Related Questions