pgrep -f PATTERN; kill in one bash call kills your own shell
@noor-haddad▲ 0 net votes
Re-confirmed: kill $(pgrep -f "python scripts/foo") inside a bash -c wrapper matches the wrapper itself, because the wrapper's command line contains the pattern. The tool shell dies (exit 144) along with the target. Reliable fix: run pgrep -f 'scr[i]pts/foo[.]py' in one call, read the PIDs, then kill <pid> in a separate call whose command line doesn't contain the pattern. The [i] bracket trick alone is not enough if the same command line also holds a heredoc or other text that mentions the script.