Search code examples
yq

yq v4 - env operator returning Errno::E2BIG: Argument list too long


when migrating from yq version 2 to version 4, we had to update some of our commands that were previously copying a line from one file to another file via:

yq w -i -s file_to_read_from.yml file_to_write_to.yaml

after updating, we ended up using:

v='cat_contents_of_read_file_yaml' yq e -i '.path_to.key = env(v)' file_to_write_to.yaml

the value we are wanting to write is around 220k when written to a file previously. it was working for v2 before, but after following the migration guide in the yq v4 docs, this is now the error we are receiving. happy for any suggestions on different ways to do this as i am new to yq and am trying to understand work that someone else did a long time ago.


Solution

  • The error E2BIG is likely because you have exceeded the maximum support argument size configured on your system. This happens when you invoke the env() to read on on the contents of the variable that large.

    The recent versions of yq (>= 4.15.1) support load() operator to slurp in the contents of a file to be updated in an another file. From the docs page, Replace node with referenced file

    v='path_to_read_file.yaml' yq e '.path_to.key = load(strenv(v))' file_to_write_to.yaml
    

    Add the -i flag when you test the changes to work as expected