mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-15 07:38:14 +00:00
1.1 KiB
1.1 KiB
Envsubst
This operator is used to replace environment variables in strings using envsubst.
To replace environment variables across all values in a document, this can be used with the recursive descent operator as follows:
yq eval '(.. | select(tag == "!!str)) |= envsubst' file.yaml
Replace strings with envsubst
Running
myenv="cat" yq eval --null-input '"the ${myenv} meows" | envsubst'
will output
the cat meows
Replace strings with envsubst, missing variables
Running
myenv="cat" yq eval --null-input '"the ${myenvnonexisting} meows" | envsubst'
will output
the meows
Replace strings with envsubst, missing variables with defaults
Running
myenv="cat" yq eval --null-input '"the ${myenvnonexisting-dog} meows" | envsubst'
will output
the dog meows
Replace string environment variable in document
Given a sample.yml file of:
v: ${myenv}
then
myenv="cat meow" yq eval '.v |= envsubst' sample.yml
will output
v: cat meow