yqexpressions are made up of operators and pipes. A context of nodes is passed through the expression and each operation takes the context as input and returns a new context as output. That output is piped in as input for the next operation in the expression. To begin with, the context is set to the first yaml document of the first yaml file (if processing in sequence using eval).
=operator takes two arguments, a
lhsexpression, which in this case is
rhsexpression which is
.ato return the node
=operator then pipes the 'root' context through the
.bto return the node
.b) to the the LHS (
.a), and it returns the now updated context:
yqexpressions have an order of precedence. The pipe
|operator has a low order of precedence, so operators with higher precedence will get evaluated first.
.a = "cat" | .b = "dog"is effectively:
(.a = "cat") | (.b = "dog").
sallyentry to have fruit: 'mango'. The incorrect way to do that is:
. | select(.name == "sally") | .fruit = "mango".
|has a low operator precedence, this will be evaluated (incorrectly) as :
(.) | (select(.name == "sally")) | (.fruit = "mango"). What you'll see is only the updated segment returned:
(. | select(.name == "sally") | .fruit) = "mango"
=) operator, and the yaml is correctly updated and returned:
=operator which we call the relative form. It's very similar to
=but with one key difference when evaluating the RHS expression.
|=takes two operands, the LHS and RHS.
.ato get the node value:
. + 1(whereas in the
=plain form it piped the original document context into the RHS) to yield: