Given config.yaml:
APP_ID: APP158
APP_NAME: "My Application"
And process-config.sh which reads the YAML entries and converts them to BASH syntax of KEY=VALUE in order to be set as environment variables:
#!/bin/bash
export $(yq e "to_entries | map(.key + \"=\" + .value) | join(\" \")" config.yaml)
echo $APP_ID
echo $APP_NAME
The following output is produced:
APP158
My
How do I retain the quotes around APP_NAME's values so that its value isn't truncated (as shown in output)?
Use the
@shencoder (available since v4.31.1) to quote a string so that it is interpretable by the shell:Note that since version 4.18.1, "yq's 'eval/e' command is the default command and no longers needs to be specified."