tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/47597: local and $() don't play well with each other

On Tue, Feb 26, 2013 at 09:24:23PM +0700, Robert Elz wrote:

> The point is that the only reason that 2.9.5 can possibly have for
> referring to 2.14 at all, is that they want functions to behave just
> like special built-in commands.   Otherwise there's no point referring
> to that section at all.   If they wanted functions to behave like every other
> command (which is what they should have wanted) they could have just said
> nothing at all, and allowed the general rules for var assignments preceding
> commands (which is not 2.14) to apply, or if they thought reinforcement was
> needed, explicitly said that a var assignment on a func call works the
> same way as on any other command (except special built-ins).
> My guess is that they didn't do that, because that wasn't the way that ksh
> worked (and still isn't the way that ksh works).

The easy way to do things is to assign in 

foo=bar command args

in the process that executes the command, so if you implement is
as a fork, it stays local if you fork before the assignment.

Shell functions, and builtins that are meant to behave like external
programs, make this complicated, if you want to avoid forking (which
is relatively expensive). I think that's why the specification might
be meant to be vague.


Home | Main Index | Thread Index | Old Index