Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: pipelines and &&
- X-seq: zsh-users 1548
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: matthi@xxxxxxxxxxxxxxxxxxxxxxxxxxx (Matthias Kopfermann), zsh-users@xxxxxxxxxxxxxxx
- Subject: Re: pipelines and &&
- Date: Mon, 25 May 1998 09:38:00 -0700
- In-reply-to: <m0ydtqL-001MsmC@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- References: <m0ydtqL-001MsmC@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author