Siddharth
Siddharth

Reputation: 192

How to add new input to the configuration file using bash script

I want to add new input to the configuration file from terminal using bash script. This is what I tried:

echo Hello, please add the new text here
read varname
sed -i "s/\<my-images=>/& $varname/" /home/myconfig
echo Image $varname has been added to the configuration. Thanks!!

/home/myconfig has

id=1
max-mb=1000
my-images=customimage

And required output is

id=1
max-mb=1000
my-images=mynewtext customimage

So mynewtext should be added after my-images= Anyway to do this?

Upvotes: 0

Views: 704

Answers (1)

robinsax
robinsax

Reputation: 1220

The problem is with the regex match you're passing to sed. Try:

sed -i "s/my-images=/&$varname /" /home/myconfig

instead.

Upvotes: 1

Related Questions