Interview Prep/Shell Scripting/Troubleshooting: tools, portability, permissions and environment

A pipeline step `yq r values.yaml image.tag` fails with `Error: unknown command "r" for "yq"`, and on another runner `yq '.image.tag' values.yaml` fails with `yq: error: argument files: can't open '.image.tag'`.

IntermediateTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer

Likely causes → There are several incompatible tools named yq. mikefarah/yq v4 (Go) removed the v3 r/w subcommands in favour of expressions. The second error comes from the Python yq (a jq wrapper, installed via pip), which expects a jq filter and different argument handling.

Diagnose →

yq --version         # "yq (https://github.com/mikefarah/yq/) version v4.44.x" vs "yq 3.x" (python)
command -v -a yq

Fix → Standardise on one: mikefarah v4 syntax is yq '.image.tag' values.yaml and yq -i '.image.tag = strenv(TAG)' values.yaml. Install a pinned binary in CI:

YQ_VERSION=v4.44.3
curl -fsSL -o /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"
chmod +x /usr/local/bin/yq

Prevent → Pin tool versions in CI images and check at start-up: yq --version | grep -q 'mikefarah' || die "mikefarah yq v4 required".

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: tools, portability, permissions and environment