如何使用bash脚本向配置文件中添加新的输入内容?

问题描述 投票:0回答:1

我想用bash脚本从终端向配置文件添加新的输入。这是我试过的。

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!!

homemyconfig有

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

而所需产出是

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

所以mynewtext应该加在my-images=后面,怎么做?

linux bash shell redhat archlinux
1个回答
1
投票

问题出在你传递给 sed. 试试吧

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

试试:

© www.soinside.com 2019 - 2024. All rights reserved.