I have an XML Plist, and I need a bash script to edit the integer value of a key in the case that that key exists, or else create the key and integer value if it does not. This is a Linux machine, so Mac OS X' defaults
command is not available.
That is, the final Pl开发者_高级运维ist would look like:
<dict>
…
<key>myKey</key>
<integer>54</integer>
…
</dict>
whether the key myKey
already existed in the original Plist or not, and where the integer value 54
is provided by a variable.
In Mac OS X I would do it like this:
defaults write ./myPlist myKey -int $(echo $myKey_value)
but like I said, no defaults
command in Linux. I tried with sed
, but apparently it can only match single lines. Maybe awk
or perl
would do, but I know almost nothing of either.
Data::Plist::XMLWriter
精彩评论