zsh-users
 help / color / mirror / code / Atom feed
From: Zoltan Hidvegi <hzoli@cs.elte.hu>
To: chrisl@cybercom.net
Cc: zsh-users@math.gatech.edu
Subject: Re: Capturing "jobs" output.
Date: Thu, 9 Jan 1997 03:19:13 +0100 (MET)	[thread overview]
Message-ID: <199701090219.DAA02248@hzoli.ppp.cs.elte.hu> (raw)
In-Reply-To: <199701082131.QAA07465@orion.cybercom.net> from Xris Laas at "Jan 8, 97 04:32:45 pm"

> I have noticed some unexpected behavior in the "jobs" builtin.  It is
> possible to redirect its output to a file, but any piping of any sort
> fails miserably.  Note these examples:
> 
> ---------------------------------
> % jobs
> [1]  + suspended (tty input)  cat
> [2]    running    sig-updater
> % jobs > foo.tmp
> % cat foo.tmp
> [1]  + suspended (tty input)  cat
> [2]    running    sig-updater
> % jobs | cat
> % echo $(jobs)
> % cat <(jobs)
> % cat =(jobs)
> ---------------------------------

Note that in all cases when jobs seemingly failed it was in a subshell.  A
subshell is created by fork() and it does not inherit child processes from its
parent so its job table is empty.  The only way to pass jobs output to a
process is using the

jobs > >(...)

syntax.  Unfortunately zsh does not wait for the >(...) process to terminate
which is probably a bug which will hopefully be fixed (together with some
other serious signal related bugs).

A simple pipe does not work since the left-hand side of a pipe is always
executed in a subshell in zsh.  In bash it is the right-hand side which is
executed in a subshell so jobs | cat works in bash but echo foo | read bar
does not set bar.  In ksh both jobs|cat and echo foo|read bar works.  I guess
that it first checks wether one of the pipe commands is not an external
command and it tries to execute the non-external side in the current shell.
That hack can be implemented in zsh (I think it would be very simple to add
this feature) but you can never rely on such thing in a portable script.
POSIX explicitely defines the behaviour unspecified here.

Zoltan


      reply	other threads:[~1997-01-09  2:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-08 21:32 Xris Laas
1997-01-09  2:19 ` Zoltan Hidvegi [this message]

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=199701090219.DAA02248@hzoli.ppp.cs.elte.hu \
    --to=hzoli@cs.elte.hu \
    --cc=chrisl@cybercom.net \
    --cc=zsh-users@math.gatech.edu \
    /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).