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

Sourcing a shared library a second time fails with `bash: CONFIG_DIR: readonly variable`, and the script exits under `set -e`.

IntermediateTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer

Likely causes → The library declares readonly CONFIG_DIR=... at load time and is sourced twice (directly and through another library).

Diagnose → grep -rn 'source\|^\. ' bin/ lib/ to see the include graph.

Fix → Add a load guard at the top of the library:

[[ -n ${_COMMON_LOADED:-} ]] && return 0
readonly _COMMON_LOADED=1

Or avoid readonly for values that callers may legitimately set.

Prevent → Libraries define functions and defaults only; they must be safe to source repeatedly.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

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