Joerg Schilling <[email protected]> wrote, on 17 Jul 2017:
>
> Martijn Dekker <[email protected]> wrote:
> 
> > 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.
> 
> ksh93 is the only genetic shell in your list...
> With genetic, i mean a shell that was derived from the Bourne Shell sources.
> 
> You could check the Bourne Shell (any version since 1984 when functions have 
> been added) and verify that the correct behavior is to execute a binary with 
> that name (overwriting the current shell process). Older Bourne Shells only 
> fail because they did not support functions, but not because "exec" did 
> behave 
> different.
> 
> > Which behaviour is correct?
> 
> The behavior that is compatibile to Bourne Shell nd ksh93.
> 
> In general, if Bourne Shell and ksh93 agree, this is most likely the right 
> behavior unless you discovered a real bug.

The intended behaviour is that of ksh88, since that was the shell the
POSIX description was based on.  I checked ksh88 shells on Solaris 11
and HP-UX 11.23 and they execute the utility, not the function.
(I tested with "ls" because they won't allow a function called "true" to
be defined, which seems to be a bug.)

However, the wording in the standard certainly does not match the intended
behaviour and needs to be corrected.

I thought initially that all uses of "command" should change to "utility",
but I think it is common for exec to be used before a pipeline.  For this
to work correctly, I suspect that exec needs to be a reserved word.

-- 
Geoff Clare <[email protected]>
The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England

Reply via email to