mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
12.33k stars 602 forks source link

Unable to use key as shell env variable #2177

Open NikonNLG opened 1 month ago

NikonNLG commented 1 month ago

Describe the bug Cannot use key from array as value for env() function

Version of yq: v4.44.3 Operating system: mac Installed via: homebrew

Input Yaml

configmap:
  values:
    FOO: ""
    BAR: ""

Command

$ FOO=bar yq 'with(.configmap.values[]; . = env(.))' test.yaml

Actual behavior

Error: value for env variable '.' not provided in env()

Expected behavior

configmap:
  values:
    FOO: bar
    BAR: ""

Additional context I tried to use various combinations, but cannot find correct one. Here's example:

$ FOO=bar yq 'with(.configmap.values[]; . = env(FOO))' test.yaml
configmap:
  values:
    FOO: "bar"
    BAR: "bar"

$ FOO=bar yq 'with(.configmap.values[]; . = env(.))' test.yaml
Error: value for env variable '.' not provided in env()

$ FOO=bar yq 'with(.configmap.values[]; . = key + "test")' test.yaml
configmap:
  values:
    FOO: "FOOtest"
    BAR: "BARtest"

$ FOO=bar BAR=baz yq 'with(.configmap.values[]; . = env(key))' test.yaml
Error: value for env variable 'key' not provided in env()