I can grep
the output of jobs
, and I can grep
the output of a function
. But why can't I grep the output of jobs
when it's in a function?
$ # yes, i can grep jobs
$ jobs
[1]+ Running vim
[2]+ Stopped matlab
$ jobs | grep vim
[1]+ Running vim
$ # yes, of course i can grep a function
$ type mockjobs
mockjobs is a function
mockjobs ()
{
echo '[1]+ Running vim banjo'
}
$ mockjobs | grep vim
[1]+ Running vim banjo
$ # now put those two together and surely I can grep???
$ type realjobs
realjobs is a function
realjobs ()
{
jobs
}
$ realjobs | grep vim
$ # Nope, WTF?
$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
$ # funny though, redirection works just fine:
$ tmpfile=$(mktemp); realjobs > $tmpfile; grep vim $tmpfile; rm $tmpfile
[1]+ Running vim
I'm not seeing a bug in the bash list, but maybe I missed it? There's reference to an issue in Bash 2.02 when jobs
is part of a pipeline, but nothing recent and in a function that I can find.
What am I missing here?
echo "$(realjobs)" | grep vi
works too.function
too.function testjobs(){jobs | grep vi}
andfunction testrealjobsgrep(){realjobs | grep vi}
.The testjobs can work,but the testrealjobsgrep can't work.