2017-07-16 20:47:52 +0200, Martijn Dekker: > 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. [...]
For completeness, (and to show the disagreement is not confined to Bourne-like shells) exec echo --help executes the external echo with csh/tcsh (those shells don't have functions) and fish and the builtin one with rc/es/akanga (at least the Unix variants, I've not tested plan9 rc). (GNU echo prints a help message upon echo --help and all those shells have a builtin echo). In busybox (not that busybox aims at POSIX compliance) env is builtin, there's a builtin sh echo, a busybox echo and the echo on the filesystem. echo --help runs the sh (ash-based) builtin env echo --help and (exec echo --help) run the busybox echo, though I beleive the behaviour can be affected by compile-time options. With the build of busybox shipped with ubuntu, the "exec" variant doesn't do any execve() (simulates it) while the "env" one does a execve("/proc/self/exe", ["echo", "--help"], environ) And there's no way (that I can tell) to call /bin/echo other than calling /bin/echo by path (/usr/bin/env echo --help (where that env is busybox) would also invoke the busybox builtin. busybox does have a which command, but like most which commands, it has a few bugs/misfeatures (in the case of busybox is seems it mishandles empty $PATH components). In most common cases, one should be able to do: "$(which echo)" --help To run the one from the filesystem. By the way, yash does have the "command -e" command discussed earlier. command -e echo To run the external echo instead of the builtin. And command -ve echo Would be the equivalent of those rare non-broken "which" implementations that are limited to report the paths of executables via $PATH lookup with the added benefit that it would also be able to query the internal command "hash" table of the shell So that would be a useful addition to the standard if only for that. See also: https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then -- Stephane