Re: 'exec' runs shell functions and builtins

2017-08-04 Thread Thorsten Glaser
Martijn Dekker dixit:

>> And this is utter nonsense, the builtin does replace the shell process,
>
>No. On mksh, 'exec builtin' is exactly equivalent to 'builtin; exit'.
>The builtin is run in the existing shell process. No
>replacing/overlaying of the shell process takes place. It's easy to
>verify this in the source code.

This is an implementation detail. Whether it’s running the same
binary is independent of this.

Compare:

ln -s $(which mksh) print
PATH=.
exec print foo

This does the same, except the “replacing the shell by the builtin”
without an actual exec is cheaper. The *functionality* of the program
is still substituted from shell to builtin.

bye,
//mirabilos
-- 
Stéphane, I actually don’t block Googlemail, they’re just too utterly
stupid to successfully deliver to me (or anyone else using Greylisting
and not whitelisting their ranges). Same for a few other providers such
as Hotmail. Some spammers (Yahoo) I do block.


Re: 'exec' runs shell functions and builtins

2017-08-04 Thread Joerg Schilling
Martijn Dekker  wrote:

> Op 02-08-17 om 22:17 schreef Thorsten Glaser:
> > Robert Elz dixit:
> > 
> >> The only way that the standard will ever say that "exec fn" is possible
> >> (exec builtin is supposed to be possible now, as (almost) all builtins
> >> are supposed to have exec*(2) versions somewhere in $PATH) is if at least
> > 
> > I repeat: the exec builtin does *not* have anything to do with
> > requiring the C code of the shell (could be COBOL for all I know)
> > to actually call an exec*(2) syscall.
>
> Actually, we have word from Geoff Clare, who is authoritative on this
> matter, that the intention of POSIX was to standardise the pre-existing
> behaviour of ksh88.[*]
>
> As both Geoff and I have verified with our own copies of ksh88 (mine on
> a Solaris 10.3 VM), 'exec' on ksh88 always overlays the shell process
> with an external command using an exec*(2) syscall. It never runs a
> shell function or a builtin.

And since this is the same behavior as seen with a traditional Bourne Shell,
and ksh93, this is obviously the "right" method.

> Another fact is that pdksh was intended to be a clone of ksh88. Thus,
> pdksh failed to clone ksh88's 'exec' properly.

There are several deviations between mksh and ksh88. Some of them could 
definitely be seen as bugs.

Jörg

-- 
 EMail:jo...@schily.net(home) Jörg Schilling D-13353 Berlin
joerg.schill...@fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/
 URL: http://cdrecord.org/private/ http://sf.net/projects/schilytools/files/'