A test script: #! /bin/sh true() { echo "exec runs function" } exec true
On zsh, pdksh and mksh, 'exec' runs the shell function. On all other POSIX shells (at least bash, dash, yash, ksh93, FreeBSD sh), it runs the external 'true' utility. Which behaviour is correct? On the one hand, exec "shall replace the shell with /command/ without creating a new process". A shell function is included in the definition of "command" (ref: 2.9.1 Simple Commands) and so this ought to work with 'exec', in which case every shell except zsh and pdksh/mksh is broken. On the other hand, can 'exec' legitimately run a shell function from the current shell (or a builtin, for that matter) when it is supposed to *replace* the shell with the command in question? Logically, you can't run something that's part of a shell process that you're supposed to have replaced. - M.