You are not logged in.
In a non-interactive shell script, command in pgrep -f 'regex' && command never runs when expected.
However, command in pgrep -f 'regex' >/dev/null && command does run when expected.
One of the scripts I use daily is affected by this (on line 27):
https://github.com/bdantas/wifi-monitor … fi-monitor
The function icon_add is supposed to return immediately (without creating an icon) if an icon already exists. If I remove >/dev/null from line 27, however, the function never returns and icons pile up in the systray.
Any idea why >/dev/null is required here? I thought the exit code of a utility (pgrep in this case) should be the same regardless of where its output is going.
Last edited by GNUser (2019-10-15 12:31:03)
Offline
I redirected the script's stderr to a log to investigate what's going on when pgrep -f 'regex' && foo fails to work as expected.
Lo and behold, a bunch of "pgrep: write error" entries show up in the log.
So it seems the issue here is that when a shell script runs in the background, pgrep gets grumpy unless its stdout is redirected somewhere (even if only to /dev/null).
Offline
I dont know much about pgrep but looking at the man page the flag -x might be warranted??
-x, --exact
Only match processes whose names (or command line if -f is speci‐
fied) exactly match the pattern.
Offline