mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-14 15:18:06 +00:00
1.5 KiB
1.5 KiB
The or
and and
operators take two parameters and return a boolean result. not
flips a boolean from true to false, or vice versa. These are most commonly used with the select
operator to filter particular nodes.
OR example
Running
yq eval --null-input 'true or false'
will output
true
AND example
Running
yq eval --null-input 'true and false'
will output
false
Matching nodes with select, equals and or
Given a sample.yml file of:
- a: bird
b: dog
- a: frog
b: bird
- a: cat
b: fly
then
yq eval '[.[] | select(.a == "cat" or .b == "dog")]' sample.yml
will output
- a: bird
b: dog
- a: cat
b: fly
Not true is false
Running
yq eval --null-input 'true | not'
will output
false
Not false is true
Running
yq eval --null-input 'false | not'
will output
true
String values considered to be true
Running
yq eval --null-input '"cat" | not'
will output
false
Empty string value considered to be true
Running
yq eval --null-input '"" | not'
will output
false
Numbers are considered to be true
Running
yq eval --null-input '1 | not'
will output
false
Zero is considered to be true
Running
yq eval --null-input '0 | not'
will output
false
Null is considered to be false
Running
yq eval --null-input '~ | not'
will output
true