zsh-users
 help / color / mirror / code / Atom feed
From: Borzenkov Andrey <Andrey.Borzenkov@siemens.com>
To: "'dominik.vogt@gmx.de'" <dominik.vogt@gmx.de>,
	"'zsh-users@sunsite.dk'" <zsh-users@sunsite.dk>
Subject: RE: why does "jobs | wc" not work?
Date: Tue, 26 Nov 2002 20:11:37 +0300	[thread overview]
Message-ID: <6134254DE87BD411908B00A0C99B044F04945AD3@MOWD019A> (raw)

> 
> 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 ^_^  ^_^




             reply	other threads:[~2002-11-26 17:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-26 17:11 Borzenkov Andrey [this message]
  -- 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

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=6134254DE87BD411908B00A0C99B044F04945AD3@MOWD019A \
    --to=andrey.borzenkov@siemens.com \
    --cc=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).