SecondBrain/reference/zsh-path-variable-collision.md

1.3 KiB

type subtype title summary tags scope last_updated date source
reference pattern/framework zsh: assigning a variable named path silently corrupts $PATH In zsh, the lowercase array variable path is linked to $PATH; assigning path=... in a script or session clobbers the executable search path and causes unrelated command-not-found failures. Use another name (tpath, fpath_ — but note fpath is also linked).
type/reference
tool/zsh
domain/shell-scripting
global 2026-07-08 2026-07-08 cc-os

zsh: path is linked to $PATH

zsh ties certain lowercase array variables to their uppercase scalar counterparts: pathPATH, fpathFPATH, cdpathCDPATH, mailpathMAILPATH, manpathMANPATH. Assigning any of them (e.g. path="/some/file" as an innocent loop variable) silently replaces the executable search path for the rest of the script/session. Symptom: unrelated tools start failing with command-not-found after a script ran.

Rule: in zsh scripts (including throwaway audit/eval scripts driven from Claude Code, whose Bash tool runs zsh on this machine), never use path, fpath, cdpath, manpath as variable names. Discovered 2026-07-08 during the Fable orchestration mini-audit (scripts fixed by renaming to tpath).