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

`echo "start" > $logfile` fails with `bash: $logfile: ambiguous redirect`

IntermediateTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer

Likely causes → The redirect target expanded to zero words (variable empty or unset) or to several words (path contains spaces), so Bash cannot pick one file.

Diagnose → declare -p logfile to see the value; check where it is set (typo, a config not loaded, a failed $(...)).

Fix → Quote and validate: logfile=${LOG_FILE:?LOG_FILE not set}; echo start >> "$logfile".

Prevent → Quote redirect targets and use set -u so unset variables fail loudly.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

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