All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Richard Retanubun <richardretanubun@ruggedcom.com>
Cc: dash@vger.kernel.org
Subject: Re: /bin/dash -c != /bin/bash -c with pgrep
Date: Tue, 24 Jan 2012 13:43:42 -0600	[thread overview]
Message-ID: <20120124194342.GC2956@burratino> (raw)
In-Reply-To: <4F1ED38A.1050401@ruggedcom.com>

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

  reply	other threads:[~2012-01-24 19:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-24 15:51 /bin/dash -c != /bin/bash -c with pgrep Richard Retanubun
2012-01-24 19:43 ` Jonathan Nieder [this message]
2012-01-24 20:17   ` Richard Retanubun
2012-01-24 20:53     ` Richard Retanubun
2012-01-24 21:03       ` Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120124194342.GC2956@burratino \
    --to=jrnieder@gmail.com \
    --cc=dash@vger.kernel.org \
    --cc=richardretanubun@ruggedcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.