mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-14 23:28:06 +00:00
1021 B
1021 B
Alternative (Default value)
This operator is used to provide alternative (or default) values when a particular expression is either null or false.
{% hint style="warning" %} Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>
{% endhint %}
LHS is defined
Given a sample.yml file of:
a: bridge
then
yq '.a // "hello"' sample.yml
will output
bridge
LHS is not defined
Given a sample.yml file of:
{}
then
yq '.a // "hello"' sample.yml
will output
hello
LHS is null
Given a sample.yml file of:
a: ~
then
yq '.a // "hello"' sample.yml
will output
hello
LHS is false
Given a sample.yml file of:
a: false
then
yq '.a // "hello"' sample.yml
will output
hello
RHS is an expression
Given a sample.yml file of:
a: false
b: cat
then
yq '.a // .b' sample.yml
will output
cat