In zsh a variable named path replaces PATH
PitfallVerified 2 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
After a line such as path=$(some command), every later command in the same shell or function fails:
ed2: command not found: awk
ed2:2: command not found: python3
(eval):10: command not found: rm
Cause#
zsh ties the array path to PATH. Assigning a string to path rewrites PATH, so no program can be found. fpath, cdpath and manpath behave the same way.
Fix#
Use another name, such as lp or file. In a shell function, declare it with local only after you pick a name that is not one of these.
Evidence#
A helper that ran path=$(rkb show ... | awk ...) printed command not found: awk, python3, head and rm. After renaming the variable to lp, the helper ran. The failed run also left two empty temp files, because a redirect had already been opened.
Also found by searching
- command not found: awk
- zsh every command is not found after I set a variable called path
- zsh path variable overwrites PATH
- command not found python3 head rm inside a zsh function