Artificial intelligent assistant

How to use pgrep inside bash script correctly? I'm running a GUI program called zeal(compiled from src) and add a script(zeal.sh) for the executable: #!/bin/bash if pgrep zeal &>/dev/null; then printf "already on\n" else ~/tools/zeal/zeal/zeal &>/dev/null & fi The strange thing is that when I run this script like `/path/to/zeal.sh`, it always tells "already on", while with `bash /path/to/zeal.sh` it correctly decides whether the process is running or not. I also checked other GUI programs(like firefox) with similar scripts and they work fine. So how can this happen and how to fix it?

The problem is that the direct call makes the script name the command name, see


cat /proc/$PID/comm


That causes `pgrep` to match. If called via `bash` then the command name is "bash".

Use


pgrep --exact zeal


instead.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2a69ce4d62e53df31ce3b294b874db94