From: Dominik Vogt <dominik.vogt@gmx.de>
To: zsh-users@sunsite.dk
Subject: Re: why does "jobs | wc" not work?
Date: Tue, 26 Nov 2002 14:33:33 +0100 [thread overview]
Message-ID: <20021126133333.GI1937@gmx.de> (raw)
In-Reply-To: <29376.1038315921@csr.com>
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
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 ^_^ ^_^
next prev parent reply other threads:[~2002-11-26 13:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2002-11-26 17:20 ` Danek Duvall
2002-11-26 13:13 ` Vincent Lefevre
2002-11-26 11:24 ` Stephane Chazelas
2002-11-26 17:11 Borzenkov Andrey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20021126133333.GI1937@gmx.de \
--to=dominik.vogt@gmx.de \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).