Quantcast
Channel: See if a script is running when using #!/usr/bin/env - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 2

See if a script is running when using #!/usr/bin/env

$
0
0

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/myscriptbash /tmp/myscriptbash /home/user/myscript with spaces

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>