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: Greg Wooledge
Subject: Re: Cannot grep jobs list when jobs called in a function
Date: Fri, 29 Apr 2016 09:44:23 -0400
User-agent: Mutt/1.4.2.3i

On Fri, Apr 29, 2016 at 03:32:22PM +0200, 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.

I don't fully understand either.  Note that the "Done" job is reported
as "date" instead of "sleep".  It would seem the subshell is trying to
keep track of processes but has become confused.

> Depending on the overall program, this might work to avoid a subshell:
> 
> if grep -q vim < <(realjobs); then ...

No, that runs "realjobs" in a background subshell.  You're thinking of
the use of a process substitution to keep the grep in the foreground,
but here it's the "realjobs" part that has to be kept in the foreground.



reply via email to

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