Replies: 2 comments
-
I don't get that error when FOO is unset or empty?
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes, thanks for checking, it seems like I was using an older version than I thought... This works as expected in the latest version, and have been since 4.22.1 (12 full months ago) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Given the following
file.yaml
:I'd like to change foo only if the FOO variable is set and not empty.
In practice, I need to do this with multiple variables and a compact solution is preferred.
The only way I have found is:
yq 'with(select(strenv(FOO)!=""); .foo=strenv(FOO))' file.yaml
This works well with strenv: I can chain several expressions like this and only the values that correspond to a set variable will be set or changed.
However, if I need to set anything different than a string (bool, integer):
yq 'with(select(strenv(FOO)!=""); .foo=env(FOO))' file.yaml
will return an error whenever FOO is unset or empty:
Error: Value for env variable 'FOO' not provided in env()
My current workaround is checking the variable in bash before attempting the substitution, which becomes unwieldy pretty soon.
Is there an alternative within yq?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions