<feed xmlns='http://www.w3.org/2005/Atom'>
<title>zsh/Test/B07emulate.ztst, branch declarednull</title>
<subtitle>[no description]</subtitle>
<id>http://git.sudomsg.com/mirror/zsh/atom/Test/B07emulate.ztst?h=declarednull</id>
<link rel='self' href='http://git.sudomsg.com/mirror/zsh/atom/Test/B07emulate.ztst?h=declarednull'/>
<link rel='alternate' type='text/html' href='http://git.sudomsg.com/mirror/zsh/'/>
<updated>2021-04-10T22:56:39Z</updated>
<entry>
<title>47794: exec: run final pipeline command in a subshell in sh mode</title>
<updated>2021-04-10T22:56:39Z</updated>
<author>
<name>brian m. carlson</name>
<email>sandals@crustytoothpaste.net</email>
</author>
<published>2021-01-04T00:23:00Z</published>
<link rel='alternate' type='text/html' href='http://git.sudomsg.com/mirror/zsh/commit/?id=f7a417388c73e7cfefb8e93fa8beba193fb1dd1f'/>
<id>urn:sha1:f7a417388c73e7cfefb8e93fa8beba193fb1dd1f</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>41668: New --emulate option on invocation.</title>
<updated>2017-09-11T09:12:17Z</updated>
<author>
<name>Peter Stephenson</name>
<email>pws@zsh.org</email>
</author>
<published>2017-09-11T09:12:17Z</published>
<link rel='alternate' type='text/html' href='http://git.sudomsg.com/mirror/zsh/commit/?id=2ef3dff65a9fc0bc69446374473ad08e6fff4755'/>
<id>urn:sha1:2ef3dff65a9fc0bc69446374473ad08e6fff4755</id>
<content type='text'>
This sets the shell emulation mode similarly to ARGV0=... which
doesn't work from other shells.

Note that this gives more comprehensive emulation than running
emulate within the shell.
</content>
</entry>
<entry>
<title>34804: refine POSIX_ALIAS change to preserve old behavior of [[ ]] conditionals</title>
<updated>2015-03-29T04:08:02Z</updated>
<author>
<name>Barton E. Schaefer</name>
<email>schaefer@zsh.org</email>
</author>
<published>2015-03-29T04:08:02Z</published>
<link rel='alternate' type='text/html' href='http://git.sudomsg.com/mirror/zsh/commit/?id=7d2b53f65bae3f16cf318103e53eb8350af6bd8a'/>
<id>urn:sha1:7d2b53f65bae3f16cf318103e53eb8350af6bd8a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>30726: make shell options passed to emulate stick along with the emulation</title>
<updated>2012-10-11T20:14:01Z</updated>
<author>
<name>Peter Stephenson</name>
<email>pws@users.sourceforge.net</email>
</author>
<published>2012-10-11T20:14:01Z</published>
<link rel='alternate' type='text/html' href='http://git.sudomsg.com/mirror/zsh/commit/?id=4b86cc48f704152ccca13c50bc3acd59b4217ecc'/>
<id>urn:sha1:4b86cc48f704152ccca13c50bc3acd59b4217ecc</id>
<content type='text'>
</content>
</entry>
<entry>
<title>30722: fix some cases where emulations or options were not propagated properly</title>
<updated>2012-10-07T19:46:46Z</updated>
<author>
<name>Peter Stephenson</name>
<email>pws@users.sourceforge.net</email>
</author>
<published>2012-10-07T19:46:46Z</published>
<link rel='alternate' type='text/html' href='http://git.sudomsg.com/mirror/zsh/commit/?id=4e2cdd795677e655f89b76b57611a196ce578432'/>
<id>urn:sha1:4e2cdd795677e655f89b76b57611a196ce578432</id>
<content type='text'>
from the emulate command
</content>
</entry>
<entry>
<title>26546, 26556: sticky emulation for functions defined in emulate ... -c ...</title>
<updated>2009-02-11T20:42:15Z</updated>
<author>
<name>Peter Stephenson</name>
<email>pws@users.sourceforge.net</email>
</author>
<published>2009-02-11T20:42:15Z</published>
<link rel='alternate' type='text/html' href='http://git.sudomsg.com/mirror/zsh/commit/?id=c7d8b0dfb8ae9670e2bc11ecf563200069a3a12f'/>
<id>urn:sha1:c7d8b0dfb8ae9670e2bc11ecf563200069a3a12f</id>
<content type='text'>
environments, plus documentation
</content>
</entry>
<entry>
<title>26545: new "emulate" test</title>
<updated>2009-02-10T20:29:49Z</updated>
<author>
<name>Peter Stephenson</name>
<email>pws@users.sourceforge.net</email>
</author>
<published>2009-02-10T20:29:49Z</published>
<link rel='alternate' type='text/html' href='http://git.sudomsg.com/mirror/zsh/commit/?id=51a646917a09f93f88ded76244780a09fae5acb0'/>
<id>urn:sha1:51a646917a09f93f88ded76244780a09fae5acb0</id>
<content type='text'>
</content>
</entry>
</feed>
