y
y
yq
Search…
Alternative (Default value)
This operator is used to provide alternative (or default) values when a particular expression is either null or false.
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>

LHS is defined

Given a sample.yml file of:
1
a: bridge
Copied!
then
1
yq '.a // "hello"' sample.yml
Copied!
will output
1
bridge
Copied!

LHS is not defined

Given a sample.yml file of:
1
{}
Copied!
then
1
yq '.a // "hello"' sample.yml
Copied!
will output
1
hello
Copied!

LHS is null

Given a sample.yml file of:
1
a: ~
Copied!
then
1
yq '.a // "hello"' sample.yml
Copied!
will output
1
hello
Copied!

LHS is false

Given a sample.yml file of:
1
a: false
Copied!
then
1
yq '.a // "hello"' sample.yml
Copied!
will output
1
hello
Copied!

RHS is an expression

Given a sample.yml file of:
1
a: false
2
b: cat
Copied!
then
1
yq '.a // .b' sample.yml
Copied!
will output
1
cat
Copied!