zsh-users
 help / color / mirror / code / Atom feed
* RE: why does "jobs | wc" not work?
@ 2002-11-26 17:11 Borzenkov Andrey
  0 siblings, 0 replies; 15+ messages in thread
From: Borzenkov Andrey @ 2002-11-26 17:11 UTC (permalink / raw)
  To: 'dominik.vogt@gmx.de', 'zsh-users@sunsite.dk'

> 
> Yes, I noticed that in the mean time.  Actually, all I am trying
> to do is fetch the number of background jobs in sh without calling
> external commands

bor@itsrm2% sleep 1000000 &
[1] 20639
bor@itsrm2% echo $#jobstates 
1
bor@itsrm2% echo $ZSH_VERSION 
4.0.4

-andrey


 and - preferrably - not writing temporary data
> to files.  It's surprisingly difficult to do:
> 
>   I=0; jobs | while read FOO; do I=$[I+1]; done; echo $I
> 
> works neither in zsh (jobs produces no output) nor in sh (the I
> variable is local to the subshell running "while").  In sh
> (actually, bash in sh mode), I can assign the output of jobs to
> a variable:
> 
>   JOBS=`jobs`
> 
> But that doesn't help because I see no way to get that as input
> into the while loop without forking it into a subshell.  In zsh,
> this should work:
> 
>   I=0; echo "$JOBS" | while read X; do I=$[I+1]; done; echo $I
> 
> But then,
> 
>   JOBS=`jobs`
> 
> fails :-/
> 
> All I can think of is to write the output in a temporary file:
> 
>   jobs > x; I=0; while read X; do I=$[I+1]; done < x; echo $I
> 
> Can anyone think of a more efficient way (speed does matter here)?
> 
> Bye
> 
> Dominik ^_^  ^_^




^ permalink raw reply	[flat|nested] 15+ messages in thread
* why does "jobs | wc" not work?
@ 2002-11-26 10:49 Dominik Vogt
  2002-11-26 10:56 ` Vincent Lefevre
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Dominik Vogt @ 2002-11-26 10:49 UTC (permalink / raw)
  To: zsh-users

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 works:

  $ sleep 1000 &
  [1] 6262
  $ jobs > foo
  $ wc foo
        1       5      29 foo   <--

But this does not:

  $ sleep 1000 &
  [1] 6262
  $ jobs | wc
        0       0       0       <-- ?

And also:

  $ echo `jobs`

  $

Is there a specific reason why jobs generates no output when
running in a pipe?

Note:  In pdksh and bash (as bash and sh), jobs works as I would
expect; csh and tcsh work like zsh.

Bye

Dominik ^_^  ^_^

P.S.:  Please CC me.



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2002-11-26 17:21 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-26 17:11 why does "jobs | wc" not work? Borzenkov Andrey
  -- strict thread matches above, loose matches on Subject: below --
2002-11-26 10:49 Dominik Vogt
2002-11-26 10:56 ` Vincent Lefevre
2002-11-26 11:09 ` Peter Stephenson
2002-11-26 11:17   ` Vincent Lefevre
2002-11-26 11:27     ` Peter Stephenson
2002-11-26 11:42   ` Dominik Vogt
2002-11-26 11:59     ` Vincent Lefevre
2002-11-26 12:08     ` Peter Stephenson
2002-11-26 12:48       ` Dominik Vogt
2002-11-26 13:05         ` Peter Stephenson
2002-11-26 13:33           ` Dominik Vogt
2002-11-26 17:20             ` Danek Duvall
2002-11-26 13:13         ` Vincent Lefevre
2002-11-26 11:24 ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).