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 08:15:56 -0400
User-agent: Mutt/1.4.2.3i

On Thu, Apr 28, 2016 at 10:38:53AM -0600, Eric Blake wrote:
> Bash has code to special-case 'jobs |' when it can obviously tell that
> you are running the jobs builtin as the sole command of the left side of
> a pipe, to instead report about the jobs of the parent shell,

Oh, that's interesting.  I didn't know that.

> but that
> special-case code cannot kick in if you hide the execution of jobs,
> whether by hiding it inside a function as you did, or by other means
> such as:
> $ eval jobs | grep vim

In general, if you want to filter the output of "jobs" or some other
builtin that changes its behavior when invoked in a subshell, then
you need to avoid the subshell.  That means no pipeline, no command
substitution, etc.  Basically that leaves you with a temporary file.

tmpfile=...  # boilerplate code to create a temp file on whatever OS
trap 'rm -f "$tmpfile"' EXIT
jobs > "$tmpfile"
if grep -q vim "$tmpfile"; then ...



reply via email to

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