Interview Prep/Shell Scripting/Troubleshooting: quoting, expansion and tool-input bugs

`sed -i "s/^image:.*/image: $IMAGE/" deploy.yaml` fails with `sed: -e expression #1, char 32: unknown option to `s'`

IntermediateTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer

Likely causes → $IMAGE contains / (ghcr.io/acme/api:1.4.2), which ends the s command early; sed then reads the rest as flags.

Diagnose → echo "s/^image:.*/image: $IMAGE/" shows the extra slashes.

Fix → Use a delimiter that cannot appear in the value, and escape & and \ in replacements:

sed -i "s|^\( *image:\).*|\1 ${IMAGE}|" deploy.yaml

Better for YAML: IMAGE=$IMAGE yq -i '.spec.template.spec.containers[0].image = strenv(IMAGE)' deploy.yaml.

Prevent → Use structural tools for structured files; escape values when sed is unavoidable.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: quoting, expansion and tool-input bugs