dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Seb <sbb@tuxfamily.org>
To: dash@vger.kernel.org
Cc: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
Subject: Re: Inconsistent behaviour between 'jobs' and 'echo "$(jobs)"'
Date: Tue, 20 Jan 2015 20:07:39 +0100	[thread overview]
Message-ID: <20150120190739.GA823@ein.free.fr> (raw)
In-Reply-To: <54BE89D6.7040101@ertelnet.rybnik.pl>

On Tue, Jan 20, 2015 at 06:01:10PM +0100, Damian Wrobel wrote:
> On 01/20/2015 09:44 AM, Seb wrote:
> >On Mon, Jan 19, 2015 at 07:01:53PM +0100, Damian Wrobel wrote:
> >
> >Hello,
> >
> >>I'm observing an inconsistent behaviour between:
> >>  jobs
> >>and
> >>  echo "$(jobs)"
> >
> >It's because the command is ran in a sub-shell, where there is indeed no
> >running job.
> >
> >Bash has a special mechanism to handle this and get the current shell
> >context returned, that's why you may feel some inconsistency here (like
> >I myself did :)
> 
> There is an application usage [1] where this case is specifically mentioned
> with a suggestion that: "For this reason, jobs is generally implemented as a
> shell regular built-in."

Indeed, it seems the standard requires, or at least expects this to
work:

 "The -p option is the only portable way to find out the
  process group of a job because different implementations
  have different strategies for defining the process group of
  the job. Usage such as $(jobs -p) provides a way of
  referring to the process group of the job in an
  implementation-independent way."


> Now it looks that even the following doesn't work in a dash:
> 
> $ jobs -p | xargs kill

For the same reason as above: each member of the pipe is ran in its own
sub-shell.


> I would prefer not to code something like the following:
> 
> $ jobs -p >/tmp/jobs-$$ && kill $(cat /tmp/jobs-$$); rm /tmp/jobs-$$

I agree it's not very nice.

++
Seb.


  reply	other threads:[~2015-01-20 19:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-19 18:01 Inconsistent behaviour between 'jobs' and 'echo "$(jobs)"' Damian Wrobel
     [not found] ` <20150120084438.GA751@ein.free.fr>
2015-01-20 17:01   ` Damian Wrobel
2015-01-20 19:07     ` Seb [this message]
2015-01-21 13:42     ` Seb

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=20150120190739.GA823@ein.free.fr \
    --to=sbb@tuxfamily.org \
    --cc=dash@vger.kernel.org \
    --cc=dwrobel@ertelnet.rybnik.pl \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).