On 24/01/12 02:43 PM, Jonathan Nieder wrote:
Hi Richard,
Richard Retanubun wrote:
/bin/dash -c "pgrep -f /usr/sbin/atftpd"; echo $?
-vs-
/bin/bash -c "pgrep -f /usr/sbin/atftpd"; echo $?
The dash version returns the PID of the grep itself and thus always succeeds.
The bash version works as expected.
As the pgrep(1) manual explains, the running pgrep or pkill process
will never report itself as a match. However, when running pgrep
through dash, it reports the process id of the shell executing pgrep,
while the bash version and recent dash versions optimize "sh -c
'single command'" to
sh -c 'exec pgrep -f /usr/sbin/atftpd'
so there is no shell process left to report.
If that "exec" is specified explicitly, the result is the same in both
shells.
Hope that helps,
Jonathan
It sure does, thanks a lot Jonathan.
As an addendum, I find using "pgrep -x atftpd" in this case also yields the
expected output in both shell.
Thanks for your time.
-- RR --
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html