[augeas-devel] Variables in path expressions

David Lutterkort lutter at redhat.com
Mon Mar 23 06:27:25 UTC 2009


When doing lots of calls to modify the same part of the tree with the C
API, or from augtool, it's really cumbersome to type the same path over and
over. To address that, there is now a new call aug_defvar with a
corresponding defvar command in augtool.

The value of a variable is the reslt of evaluating a path expression, which
can be a nodeset, a number or a string. As an example, in augtool you can
now write

  defvar hosts /files/etc/hosts/*
  defvar comment "'#comment'"
  match "$hosts[label() != $comment]"

to list all host nodes that are not comments.

Note that variables hold th eresult of evaluating a path expression, they
are not a shorthand for textual substitution within path expressions. That
means that with the above variables, the following commands in augtool

  set /files/etc/hosts/42/ipaddr 10.0.0.1
  match "$hosts[label() != $comment]"

you will not see the new node. For that, you'd have to reevaluate the
definition of hosts after the 'set'.

There is one wrinkle to that: when you remove nodes from the tree that are
currently in a nodeset, they are also removed from that nodeset.

The patch series contains a lot of refactorings to set things up. The meat
of the variable definitions is in 9/11 and 10/11.

David




More information about the augeas-devel mailing list