[augeas-devel] xpath expression to query grub.conf

David Lutterkort lutter at redhat.com
Fri Oct 23 17:42:22 UTC 2009


On Fri, 2009-10-23 at 13:47 +0200, Ludwin Janvier wrote:
> [ my question is more a user issue but I didn't find a user mailing
> list. If there's one, could you give redirect me to it ? ]

You've come to the right place.

> I got a grub.conf which looks like :
> 
> /files/etc/grub.conf/title[1] = "Fedora (2.6.30.5-43.fc11.i686.PAE)"
> /files/etc/grub.conf/title[1]/root = "(hd0,3)"
> ...
> /files/etc/grub.conf/title[3] = "WindowsXP"
> /files/etc/grub.conf/title[3]/rootnoverify = "(hd0,1)"
> /files/etc/grub.conf/title[3]/chainloader = "+1"
> 
> my primary goal is to move title = "Windows XP" (which can be
> title[3]... or not)  before title[1].
> 
> So I create a new node :
> > ins title before /files/etc/grub.conf/title[1]
> 
> And I would use mv to move "Windows XP" in the new title[1]
> mv could do the trick if I knew how to get "Windows XP" with an xpath.
> "match" can get the node :
> > match /files/etc/grub.conf/* "Windows XP"
> /files/etc/grub.conf/title[3]

This form of match actually lists a whole bunch of nodes, then gets
their value, and then pulls out the one whose value is the 2nd argument
to match.

What you are looking for is one path expression that does it all:

  match "/files/etc/grub.conf/title[. = 'Windows XP']"

(the "" around the whole thing are only needed in augtool, otherwise it
will split the path expression into several arguments for match)

What you want to do can be done in the following way:
        defvar grub /files/etc/grub.conf
        ins title before $grub/title[1]
        mv "$grub/title[. = 'Windows XP']" $grub/title[1]

> But this result is useless for mv (I can't set this in a var, can I ?).
> I tried to find a single xpath to get it, with no success
> 
> > match "/files/etc/grub.conf/*[title='Windows XP']"
>   (no matches)

This one is very close, but you stumbled over one level in the tree;
when the [..] is evaluated, the current node is already a title - the
predicate then looks for a child node with label 'title', which doesn't
exist.

This was actually a nice problem - I had no idea that mv would let you
do this, but it seems itdoes ;)

David





More information about the augeas-devel mailing list