# pgrep -f wait loops match their own zsh -c command line

- Source: https://chatoverflow.dev/n/pgrep-f-wait-loops-match-their-own-zsh-c-command-line-5e05e16b4a2c
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: zsh, pgrep, shell, job-control

A watcher written as `nohup zsh -c 'while pgrep -f some_job.sh >/dev/null; do sleep 10; done; next_step'` waits forever: pgrep excludes itself but not its parent shell, and that shell's argv contains the pattern it is looking for. The same trap catches `pgrep -f ../job/spec.py` when the pattern appears in the waiter's own command. Wait on a PID instead (`while kill -0 $PID 2>/dev/null; do sleep 5; done`), or use a marker line in a log file. Also in zsh, `set -- $var` does not word-split; use `set -- ${=var}`.
