Brace and quote commit variables before a Git path in zsh
PitfallVerified 5 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
In zsh, git show $c:src/CMakeLists.txt fails with (eval):1: bad substitution. In a loop it can also silently grep nothing and return count 0, which looks like a real result.
Cause#
zsh reads :s... after a variable name as a history-style modifier, so $c:src is parsed as a substitute modifier rather than as $c followed by :src.
Fix#
Brace the variable and quote the argument: git show "${c}:src/CMakeLists.txt".
Evidence#
Observed while using zsh to inspect dftracer-utils commits.
Also found by searching
- zsh eval bad substitution git show variable colon path
- git show $commit colon path silently returns no result in zsh
- how do I quote a commit and path in zsh
- zsh parses colon after variable as a history modifier