bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cannot grep jobs list when jobs called in a function


From: Chet Ramey
Subject: Re: Cannot grep jobs list when jobs called in a function
Date: Wed, 25 May 2016 20:09:17 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.1.0

On 4/29/16 9:32 AM, Reuti wrote:

> I understand that the behavior of the builtin `jobs` changes, in case it 
> discovers that it's run a subshell. But what is happening here:
> 
> $ sleep 300 &
> [1] 31766
> $ function lister() { date; jobs; }
> $ lister
> Fri Apr 29 15:29:46 CEST 2016
> [1]+  Running                 sleep 300 &
> $ lister | cat
> Fri Apr 29 15:30:00 CEST 2016
> [1]   Done                    date
> 
> My question is: why does the `date` command show up as "done" at all? I would 
> expect the output to be just empty.

It's being printed by the shell that is started to run the `lister'
function in the pipeline.  That shell has its own jobs list; it doesn't
inherit one from its parent.  Ordinarily, that shell wouldn't print
the status of any jobs; they would just disappear from the list (which
is always kept).  You asking for them with the `jobs' builtin makes
them show up.

Technically, that shell is interactive, so the job sticks around until
the shell exits or it prints its next interactive prompt (which will
not happen, obviously).

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]