bash脚本编辑XML文件 [英] bash script to edit xml file
问题描述
我想编辑一个程序,它是一个XML的配置文件:
I want to edit the config file of a program that is an XML:
<software>
<settings>
...
<setting name="local directory" type="string">/home/username/</setting>
...
</settings>
</software>
什么是从一个bash脚本做到这一点,最简单的方法?
What is the easiest way to do this from a bash script?
感谢
推荐答案
根据您想要做什么,你可能需要使用一些特定于XML的工具(来处理字符编码,以保持XML良构等) 。您可以使用普通的面向行的工具,但除非你小心(或做一些琐碎的),你可以轻松地创建不兼容的XML。
Depending on what you want to do, you may want to use some XML-specific tooling (to handle character encodings, to maintain XML well-formedness etc.). You can use the normal line-oriented tools, but unless you're careful (or doing something trivial) you can easily create non-compliant XML.
我使用 XMLStarlet 命令行设置。这是一组命令行实用程序专门分析/操作XML。
I use the XMLStarlet command line set. It's a set of command line utilities for specifically parsing/manipulating XML.
这篇关于bash脚本编辑XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!