Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://mikefarah.gitbook.io/yq/recipes#export-as-environment-variables-script-or-any-custom-format doesn't work #1932

Closed
jakub-bochenski opened this issue Feb 1, 2024 · 1 comment
Labels

Comments

@jakub-bochenski
Copy link

$ yq --version
yq (https://github.com/mikefarah/yq/) version v4.40.5
$ echo 'simple: string0
simpleArray:
  - apple
  - banana
  - peach
deep:
  property: value
  array:
    - cat' | yq '.. |(
        ( select(kind == "scalar" and parent | kind != "seq") | (path | join("_")) + "='" + . + "'"),
        ( select(kind == "seq") | (path | join("_")) + "=(" + (map("'" + . + "'") | join(",")) + ")")
)'
simple= + . + 
deep_property= + . + 
simpleArray=( + . + , + . + , + . + )
deep_array=( + . + )

I believe this is caused by wrong escaping.
If you use single quote to quote the string, you need to escape single quotes inside...

@mikefarah
Copy link
Owner

Yes you're absolutely right - it should be:

yq '.. |(
        ( select(kind == "scalar" and parent | kind != "seq") | (path | join("_")) + "='\''" + . + "'\''"),
        ( select(kind == "seq") | (path | join("_")) + "=(" + (map("'\''" + . + "'\''") | join(",")) + ")")
)' test.yaml 

I'll update the docs 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants