Zsh Mailing List Archive
Messages sorted by:
Re: why does "jobs | wc" not work?
- X-seq: zsh-users 5535
- From: Dominik Vogt <dominik.vogt@xxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: why does "jobs | wc" not work?
- Date: Tue, 26 Nov 2002 14:33:33 +0100
- In-reply-to: <29376.1038315921@xxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20021126124814.GH1937@xxxxxx> <29376.1038315921@xxxxxxx>
- Reply-to: dominik.vogt@xxxxxx
On Tue, Nov 26, 2002 at 01:05:21PM +0000, Peter Stephenson wrote:
> Dominik Vogt wrote:
> > From a user's point of view I think it would be better to fork the
> > right hand side of the pipe. This way, the left hand side always
> > generates the same output, regardless of the context in which it
> > is used.
> If you look in the completion system, you will see various places where
> we do stuff on the lines of
> output_some_values | while read line; ...
> in order to process values for the current shell, and very few where we
> need to output transient data from shell builtins. I think jobs is the
> only common case.
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 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
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
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)?
Dominik ^_^ ^_^
Messages sorted by: