Forrest logo
back to the yq tool

yq:tldr:b7ff6

yq: Set (or overwrite) a key to a value in a file (v4+).
$ yq eval '.${key} = "${value}"' --inplace ${filename-yaml}
try on your machine

This command uses the yq tool to evaluate a YAML file and update its content. Here is the breakdown of the command:

  • yq eval: Invoke the yq tool in eval mode, which allows executing expressions to manipulate YAML files.
  • '.${key} = "${value}"': This is the expression that will be evaluated. It sets a YAML key (specified by the variable key) to a new value (specified by the variable value). The . at the beginning refers to the root level of the YAML document.
  • --inplace: This flag indicates that the changes should be made directly to the input file instead of printing the modified content to the console.
  • ${filename-yaml}: This is a variable representing the filename/path of the YAML file that will be modified. The actual value of the variable will be substituted in the command.

Overall, when this command is executed, it will update the YAML file by setting the value of the specified key to the specified value. The update will be made directly in the input file.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the yq tool