I have tried migrating the shebang for my bash scripts from #!/bin/bash to #!/usr/bin/env bash, and some of them were broken because they relied on this code that checks for existing instances of themselves runnning, and which works only with #!/bin/bash:
$ pidof -x myscript -o %PPID
What I would like to know is how can I reliably check if a script called by env is running, since most solutions I have tried will involve some dirty regex, and stilll end up being unreliable:
$ pgrep -f '(^|/)myscript(\s|$)'
Considering the path to my script is /home/user/myscript, the above code may return the PID for the following undesired commands:
editor /home/user/myscript
bash /tmp/myscript
bash /home/user/myscript with spaces