我想用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=后面,怎么做?
问题出在你传递给 sed
. 试试吧
sed -i "s/my-images=/&$varname /" /home/myconfig
试试: