NetBSD-Bugs archive

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

bin/47608: ``var=value func-call'' does not export var in the function (+FIX)

>Number:         47608
>Category:       bin
>Synopsis:       ``var=value func-call'' does not export var in the function 
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 02 18:30:00 +0000 2013
>Originator:     Robert Elz
>Release:        NetBSD  (current as of 2013-03-02 & all earlier supported 
        Prince of Songkla University
System: NetBSD 5.1_STABLE NetBSD 5.1_STABLE 
(JADE-1.12-20120130) #27: Tue Jan 31 05:20:31 ICT 2012 i386
Architecture: i386
Machine: i386
        The syntax
                var=value command
        is supposed to add var (with value "value") to the environment
        of command.   If command is an executable, it does.  If
        command is a function, it doesn't - the function gets to see
        the value of ${var} as being "value", but any commands it
        runs do not.

        unset var
        myfunc() { env | grep '^var=' ; echo "var was ${var} in myfunc"; }
        var=foo myfunc

        The output should be:

        var was foo in myfunc

        But is instead:

        var was foo in myfunc

        The "env" invocation does not send a value for "var" to grep.

        Note this is (kind of) related to the long discussion on
        tech-userlevel on what should be the value in var after myfunc
        finishes,  but this one is much simpler, non-controversial,
        and clearly a bug in our sh.

        Apply the patch below.   It is kind of trivial, but works...

--- eval.c.bug  2013-01-03 15:54:42.000000000 +0700
+++ eval.c      2013-03-03 01:00:48.000000000 +0700
@@ -947,7 +947,7 @@
                savehandler = handler;
                handler = &jmploc;
-               listmklocal(varlist.list, 0);
+               listmklocal(varlist.list, VEXPORT);
                /* stop shell blowing its stack */
                if (++funcnest > 1000)
                        error("too many nested function calls");

Home | Main Index | Thread Index | Old Index