From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20246 invoked from network); 25 May 1998 16:46:08 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 25 May 1998 16:46:08 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id MAA07724; Mon, 25 May 1998 12:38:38 -0400 (EDT) Resent-Date: Mon, 25 May 1998 12:38:23 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980525093801.ZM13568@candle.brasslantern.com> Date: Mon, 25 May 1998 09:38:00 -0700 In-Reply-To: Comments: In reply to matthi@finlandia.Infodrom.North.DE (Matthias Kopfermann) "pipelines and &&" (May 25, 10:46am) References: X-Mailer: Z-Mail (4.0b.820 20aug96) To: matthi@finlandia.Infodrom.North.DE (Matthias Kopfermann), zsh-users@math.gatech.edu Subject: Re: pipelines and && MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"B600K2.0.Bu1.-vPQr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1548 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On May 25, 10:46am, Matthias Kopfermann wrote: } Subject: pipelines and && } } I would very much like to know how sublists and pipelines are done: } I read the following without understanding how to do it: } } "If two pipelines are separated by ``&&'', the second } pipeline is executed only if the first is successful The real confusion comes from this text: A "pipeline" is a sequence of one or more commands separated by `|' or `|&'. `|&' is shorthand for `2>&1 |'. The standard output of each command is connected to the standard input of the next command in the pipeline. How can one command be separated by `|' or `|&'? That paragraph goes on to say: If a pipeline is preceded by `coproc', it is executed as a coprocess; a two-way pipe is established between it and the parent shell. The shell can read from or write to the coprocess by means of the `>&p' and `<&p' redirection operators. The value of a pipeline is the value of the last command. If a pipeline is not preceded by `!', the value of that pipeline is the logical `NOT' of the value of the last command. That's not just confusing, it's wrong (extra `not' in the last sentence). Better text (I don't have the yodl doc handy to make a patch): A "pipeline" is either a simple command, or a sequence of two or more simple commands where each command is separated from the next by `|' or `|&'. The standard output of each command is connected to the standard input of the next. `|&' is shorthand for `2>&1 |' which connects both the standard output and the standard error of the command to the standard input of the next. The value of a pipeline is the value of the last command, unless the pipeline is preceded by `!' in which case the value is the logical `NOT' of the value of the last command. If a pipeline is preceded by `coproc', it is executed as a coprocess; a two-way pipe is established between it and the parent shell. The shell can read from or write to the coprocess by means of the `>&p' and `<&p' redirection operators or with `print -p' and `read -p'. A pipeline cannot be preceded by both `coproc' and `!'. Might as well fix the rest, too, though it's not as bad: A "sublist" is either a single pipeline, or a sequence of two or more pipelines separated by `&&' or `||'. If two pipelines are separated by `&&', the second pipeline is executed only if the first succeeds (returns a zero value). If two pipelines are separated by `||', the second is executed only if the first fails (returns a nonzero value). Both operators have equal precedence and are left associative. A "list" is a sequence of zero or more sublists, in which each sublist is terminated by `;', `&', `&|', `&!', or a newline. This terminator may optionally be omitted from the last sublist in the list when the list appears as a complex command inside `(' `)' or `{' `}'. When a sublist is terminated by `;' or newline, the shell waits for it to finish before executing the next sublist. If a sublist is terminated by a `&', `&|', or `&!', the shell executes it in the background, and does not wait for it to finish. Note that I've replaced the term "list" with "sublist" in a couple of key places in the text above. The original paragraph implies that e.g. sleep 10 ; echo hello & will background the entire list; that's incorrect -- the sleep completes before the echo is backgrounded. This is the same as bash, but not the same as csh (I'm not sure about ksh). I'd consider moving the stuff about optionally omitting the terminator to the sections about ( LIST ) and { LIST } under Complex Commands, and not even mention omission of terminators in the section on simple commands. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com