From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8185 invoked by alias); 25 Jul 2017 22:10:21 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41462 Received: (qmail 6300 invoked from network); 25 Jul 2017 22:10:21 -0000 X-Qmail-Scanner-Diagnostics: from kahlil.inlv.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(37.59.109.123):SA:0(-0.0/5.0):. Processed in 3.509314 secs); 25 Jul 2017 22:10:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: martijn@inlv.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at inlv.org does not designate permitted sender hosts) To: Zsh hackers list From: Martijn Dekker Subject: [BUG] 'exec' runs shell functions and builtins Message-ID: Date: Tue, 25 Jul 2017 22:49:33 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit 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