mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-06-01 12:56:04 +02:00
f7a417388c
zsh typically runs the final command in a pipeline in the main shell instead of a subshell. However, POSIX specifies that all commands in a pipeline run in a subshell, but permits zsh's behavior as an extension. The default /bin/sh implementations on various Linux distros and the BSDs always use a subshell for all components of a pipeline. Since zsh may be used as /bin/sh in some cases (such as macOS Catalina), it makes sense to have the common sh behavior when emulating sh, so do that by checking for being the final item of a multi-item pipeline and creating a subshell in that case. From the comment above execpline(), we know the following: last1 is a flag that this command is the last command in a shell that is about to exit, so we can exec instead of forking. It gets passed all the way down to execcmd() which actually makes the decision. A 0 is always passed if the command is not the last in the pipeline. […] If last1 is zero but the command is at the end of a pipeline, we pass 2 down to execcmd(). So there are three cases to consider in this code: • last1 is 0, which means we are not at the end of a pipeline, in which case we should not change behavior. • last1 is 1, which means we are effectively running in a subshell, because nothing that happens due to the exec is going to affect the actual shell, since it will have been replaced. So there is nothing to do here. • last1 is 2, which means our command is at the end of the pipeline, so in sh mode we should create a subshell by forking. input is nonzero if the input to this process is a pipe that we've opened. At the end of a multi-stage pipeline, it will necessarily be nonzero. Note that several of the tests may appear bizarre, since most developers do not place useless variable assignments directly at the end of a pipeline. However, as the function tests demonstrate, there are cases where assignments may occur when a shell function is used at the end of a command. The remaining assignment tests simply test additional cases, such as the use of local, that would otherwise be untested. |
||
---|---|---|
.. | ||
.cvsignore | ||
.distfiles | ||
A01grammar.ztst | ||
A02alias.ztst | ||
A03quoting.ztst | ||
A04redirect.ztst | ||
A05execution.ztst | ||
A06assign.ztst | ||
A07control.ztst | ||
B01cd.ztst | ||
B02typeset.ztst | ||
B03print.ztst | ||
B04read.ztst | ||
B05eval.ztst | ||
B06fc.ztst | ||
B07emulate.ztst | ||
B08shift.ztst | ||
B09hash.ztst | ||
B10getopts.ztst | ||
B11kill.ztst | ||
B12limit.ztst | ||
B13whence.ztst | ||
C01arith.ztst | ||
C02cond.ztst | ||
C03traps.ztst | ||
C04funcdef.ztst | ||
C05debug.ztst | ||
D01prompt.ztst | ||
D02glob.ztst | ||
D03procsubst.ztst | ||
D04parameter.ztst | ||
D05array.ztst | ||
D06subscript.ztst | ||
D07multibyte.ztst | ||
D08cmdsubst.ztst | ||
D09brace.ztst | ||
E01options.ztst | ||
E02xtrace.ztst | ||
Makefile.in | ||
P01privileged.ztst | ||
README | ||
V01zmodload.ztst | ||
V02zregexparse.ztst | ||
V03mathfunc.ztst | ||
V04features.ztst | ||
V05styles.ztst | ||
V06parameter.ztst | ||
V07pcre.ztst | ||
V08zpty.ztst | ||
V09datetime.ztst | ||
V10private.ztst | ||
V11db_gdbm.ztst | ||
V12zparseopts.ztst | ||
V13zformat.ztst | ||
V14system.ztst | ||
W01history.ztst | ||
W02jobs.ztst | ||
X02zlevi.ztst | ||
X03zlebindkey.ztst | ||
X04zlehighlight.ztst | ||
Y01completion.ztst | ||
Y02compmatch.ztst | ||
Y03arguments.ztst | ||
Z01is-at-least.ztst | ||
Z02zmathfunc.ztst | ||
comptest | ||
list-XFails | ||
runtests.zsh | ||
ztst.zsh |
There are now different sections, expressed by the first letter in the scripts names: A: basic command parsing and execution B: builtins C: shell commands with special syntax D: substititution E: options P: privileged (needs super-user privileges) V: modules W: builtin interactive commands and constructs X: line editing Y: completion Z: separate systems and user contributions You will need to run these by using `make test' in the Test subdirectory of the build area for your system (which may or may not be the same as the Test subdirectory of the source tree), or the directory above. You can get more information about the tests being performed with ZTST_verbose=1 make check (`test' is equivalent to `check') or change 1 to 2 for even more detail. Individual or groups of tests can be performed with make TESTNUM=C02 check or make TESTNUM=C check to perform just the test beginning C02, or all tests beginning C, respectively. Instructions on how to write tests are given in B01cd.ztst, which acts as a model.