bis*_*hop 7 bash pipe function jobs subshell
我可以grep
输出jobs
,我可以grep
输出 a function
。但是为什么我不能jobs
在函数中grep 输出呢?
$ # 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
Run Code Online (Sandbox Code Playgroud)
我在 bash 列表中没有看到错误,但也许我错过了?在 Bash 2.02 中提到了一个问题,当它jobs
是管道的一部分时,但在我能找到的功能中没有最新的。
我在这里缺少什么?