Hi!
As described in
this Stack Overflow question, I'm experiencing what appears to me as unusual behavior with the jobs command, when jobs is within a function. In short:
$ jobs
[1]+ Running vim
[2]+ Stopped matlab
$ type realjobs
realjobs is a function
realjobs ()
{
jobs
}
$ realjobs | grep vim
$ # no output???
$ # funny though, redirection works just fine:
$ tmpfile=$(mktemp); realjobs > $tmpfile; grep vim $tmpfile; rm $tmpfile
[1]+ Running vim
Commenters on the SO question have also reported unusual results with combinations on this theme. Am I misunderstanding some behavior of the jobs built-in or functions?
System information follows:
$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
$ # this is an Amazon EC2 machine
$ uname -a
Linux trencher 4.1.17-22.30.amzn1.x86_64 #1 SMP Fri Feb 5 23:44:22 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
I've also downloaded the latest from Savannah, and compiled: same behavior. Example:
$ less try.bash
set -x
echo $BASH_VERSION
function realjobs() {
jobs
}
sleep 20 &
jobs
jobs | grep sleep
realjobs
realjobs | grep sleep
$ ./bash try.bash
+ echo '4.3.42(1)-release'
4.3.42(1)-release
+ jobs
[1]+ Running sleep 20 &
+ grep sleep
+ jobs
[1]+ Running sleep 20 &
+ realjobs
+ jobs
[1]+ Running sleep 20 &
+ sleep 20
+ grep sleep
+ realjobs
+ jobs
Here's the relevant machine details from bashbug for that build:
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu' -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g -O2
uname output: Linux trencher 4.1.17-22.30.amzn1.x86_64 #1 SMP Fri Feb 5 23:44:22 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu
Thanks,
bishop