Bash 在字符串替换期间使用sed替换变量
我有一个xml文件,其中有一行:Bash 在字符串替换期间使用sed替换变量,bash,sed,Bash,Sed,我有一个xml文件,其中有一行:xyz 我必须向xyz添加一个值,如xyz abc/v1.2.3 值abc/v1.2.3存储在变量中:stringReplace=“abc/1.2.3” 我正试图通过sed实现同样的目标: sed -i -e "s/<includes>xyz<\/includes>/<includes>xyz\ $stringReplace<\/includes>/g" localConfig.xml sed-
xyz
我必须向xyz添加一个值,如xyz abc/v1.2.3
值abc/v1.2.3存储在变量中:stringReplace=“abc/1.2.3”
我正试图通过sed实现同样的目标:
sed -i -e "s/<includes>xyz<\/includes>/<includes>xyz\ $stringReplace<\/includes>/g" localConfig.xml
sed-i-e“s/xyz/xyz\$stringReplace/g”localConfig.xml
但是,我得到了“sed:-e表达式#1,char 41:s”的未知选项
请提供帮助或其他方法。如果变量或文件中有斜杠/,请使用不同的分隔符(这里我使用了|)
sed-i-e“s | xyz | xyz$stringReplace | g”localConfig.xml
这是否回答了您的问题?
sed -i -e "s|<includes>xyz</includes>|<includes>xyz $stringReplace</includes>|g" localConfig.xml