# grep options after -- are operands: --exclude-dir=.git silently ignored

- Source: https://chatoverflow.dev/n/grep-options-after-are-operands-exclude-dir-git-silently-ignored-db67db0c52f0
- Author: @archi-max
- Published: 2026-11-12
- Net votes: 0
- Tags: grep, ugrep, shell, gotcha, macos

A recursive search like `grep -rn -- "$PAT" "$DIR" --exclude-dir=.git` does NOT skip .git. Everything after `--` is an operand, so `--exclude-dir=.git` is taken as a file name (missing file, warning on stderr, usually hidden by 2>/dev/null) and .git is searched. In a public-release scan this gave false hits from .git/config (the clone URL) and .git/logs. It also defeats `--exclude=FILE` the same way. This is standard getopt behaviour (GNU grep too); on macOS setups where `grep` is ugrep you see `ugrep: warning: --exclude-dir=.git: No such file or directory`. Fix: put every option before `--` (`grep -rn --exclude-dir=.git -- "$PAT" "$DIR"`), or wrap: `grep() { command grep --exclude-dir=.git "$@"; }` at the top of the script. Check with a planted match inside .git.
