zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [BUG] 'exec' runs shell functions and builtins
Date: Tue, 25 Jul 2017 22:49:33 +0100	[thread overview]
Message-ID: <fd2a215e-5832-f135-c69d-a1f4e1a6c99e@inlv.org> (raw)

In zsh, 'exec' looks up shell functions and builtins before external
commands, and if it finds one it appears to do the equivalent of running
the function or builtin followed by 'exit'. This is different from most
other shells and turns out[1] to be a bug in POSIX terms; 'exec' is
supposed to launch a program that overlays the current shell[2],
implying the program launched by 'exec' is always external to the shell.

This means that
    (exec commandname arguments ...)
is a POSIXly correct way of guaranteeing the execution of an external
command without specifying the path (something the "command" command
doesn't do in POSIX mode). This was confirmed the other day by Geoff
Clare and Chet Ramey on austin-group-l. (I seem to recall Bart asked on
this list quite some time ago if POSIX provides for a way to do this.)

This behaviour also appears to be contrary to the documentation in
zshbuiltins(1) ("Replace the current shell with an external command
rather than forking").

Test script:

testFn() {
        exec :
}
if (PATH=/dev/null exec testFn) 2>/dev/null; then
        echo "this shell execs both functions and builtins"
fi

(The only other POSIX-ish shell that zsh has this in common with is
pdksh/mksh. In pdksh this is definitely a bug as this behaviour differs
from ksh88 which pdksh is supposed to be a clone of. The POSIX spec is
also based on ksh88 behaviour.)

Confirmed down to 4.3.17 (I didn't check older versions).

- M.

[1] https://www.mail-archive.com/austin-group-l@opengroup.org/msg01469.html

[2]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_20_14


             reply	other threads:[~2017-07-25 22:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170725221050epcas4p131de822f47289e279c7de12de0d6c127@epcas4p1.samsung.com>
2017-07-25 21:49 ` Martijn Dekker [this message]
2017-07-26  9:23   ` Peter Stephenson
2017-07-26  9:27     ` Peter Stephenson
2017-07-26 12:53   ` Peter Stephenson
2017-08-04 15:34     ` Stephane Chazelas
2017-07-26 17:46   ` Bart Schaefer
2017-07-26 17:48     ` Bart Schaefer
2017-07-27  9:02     ` Peter Stephenson
2017-07-28 17:58       ` Bart Schaefer
2017-08-11 15:10         ` Kamil Dudka
2017-08-11 15:25           ` Peter Stephenson
2017-08-14  7:19             ` Kamil Dudka

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=fd2a215e-5832-f135-c69d-a1f4e1a6c99e@inlv.org \
    --to=martijn@inlv.org \
    --cc=zsh-workers@zsh.org \
    /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).