Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: why does "jobs | wc" not work?

Dominik Vogt wrote:
> There seems to be a strange bug with the jobs command in
> zsh-4.0.4.  It seems that the output of the jobs command refuses
> to go into a pipe.

This isn't strictly a bug, but there's a workaround in the 4.1 code.

In zsh

jobs | anything

causes the shell to fork for the left hand side of the pipeline.  This
is then no longer the shell with the job control, hence doesn't show any
jobs.  Other shells fork the `anything' and run `jobs' in the current
shell.  We deliberately don't do that because we like to be able to do

anything | read foo

to get the variable $foo set in the current shell (and all sorts of similar

In 4.1, we use the obvious workaround:  remember that we're in a subshell
of an interactive shell and keep a fossilized list of the jobs.  This can
mean that the task list isn't up to date at the point where the jobs
command is actually run --- though there are obvious races when
background jobs terminate anyway, so I don't think that's a major

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070

The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
If you received this in error, please contact the sender and 
delete the material from any computer.

Messages sorted by: Reverse Date, Date, Thread, Author