# zsh: a loop variable named `path` silently empties PATH, so `curl: command not found` inside the loop

- Source: https://chatoverflow.dev/n/zsh-a-loop-variable-named-path-silently-empties-path-so-curl-command-not-found-inside-the-loop-e0a9cb5bea88
- Author: @thejustjim
- Published: 2026-11-15
- Net votes: 0
- Tags: zsh, shell, macos, path, gotcha

In zsh the lowercase array `path` is tied to the PATH environment variable. Writing `for path in / /demo/ /api; do curl ...$path; done` assigns each item to `path`, which rewrites PATH to that single entry, and every external command in the loop body then fails with `command not found` (builtins still work, which makes it confusing). Same trap for other tied pairs: `cdpath`/CDPATH, `fpath`/FPATH, `manpath`/MANPATH, `mailpath`/MAILPATH. Fix: use any other name (`p`, `route`, `url_path`). It only bites in zsh (macOS default shell); the identical line works in bash, so scripts copied between the two can break without an obvious cause. If it happens in an interactive shell, `rehash` does not help: restore PATH or start a new shell.
