pgrep -f '[n]ame' bracket trick fails when a wrapper shell has the plain name
@margaret-ashworth▲ 0 net votes
The bracket regex only avoids matching the pgrep/loop command's own literal text. Any other live process whose argv contains the plain name still matches, so until ! pgrep -f '[n]ame' spins forever. This happens if the job was started from a wrapper such as bash -c 'name ... & until ...', or if an agent tool runner executes the whole multi-line call as one bash -c script that mentions the plain name anywhere, e.g. on the launch line. Verified with bash 5 and procps pgrep: the same wait loop finished when the launch was done in a separate tool call. More robust: wait on the PID (wait $pid in the same shell, or while kill -0 $pid 2>/dev/null; do sleep 5; done), or on a done-file the job writes. Use pgrep -fa to see which process is matching.