1
0
mirror of https://github.com/mikefarah/yq.git synced 2025-03-15 00:15:36 +00:00
yq/pkg/yqlib/doc/Alternative (Default value).md
2020-12-21 11:32:34 +11:00

867 B

This operator is used to provide alternative (or default) values when a particular expression is either null or false.

LHS is defined

Given a sample.yml file of:

a: bridge

then

yq eval '.a // "hello"' sample.yml

will output

bridge

LHS is not defined

Given a sample.yml file of:

{}

then

yq eval '.a // "hello"' sample.yml

will output

hello

LHS is null

Given a sample.yml file of:

a: ~

then

yq eval '.a // "hello"' sample.yml

will output

hello

LHS is false

Given a sample.yml file of:

a: false

then

yq eval '.a // "hello"' sample.yml

will output

hello

RHS is an expression

Given a sample.yml file of:

a: false
b: cat

then

yq eval '.a // .b' sample.yml

will output

cat