NetBSD-Bugs archive

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

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

>Number:         47597
>Category:       bin
>Synopsis:       local and $() don't play well with each other
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 26 02:45:00 +0000 2013
>Originator:     Julio Merino
>Release:        NetBSD 6.99.17
System: NetBSD 6.99.17 NetBSD 6.99.17 (GENERIC) #0: Sat Feb 23 
07:37:14 EST 2013
Architecture: x86_64
Machine: amd64
        The following test case exhibits an error with /bin/sh and /bin/ksh
        that does not happen with bash:

f() {
        echo "before setting var"
        local var=$(echo a=b --c=d)
        echo "var is: ${var}"
        echo "after setting var"

echo "before calling f"
echo "after calling f"

        Running this script with /bin/sh results in the following output:

$ sh ~/
before calling f
before setting var
var is: a=b
after setting var
/home/jmmv/ --c: bad variable name

        And with /bin/ksh:

$ ksh ~/
before calling f
before setting var
/home/jmmv/[11]: typeset: --c=d: not identifier
after calling f

        Surrounding the $() with double quotes makes this work with both
        shells and mimics the behavior of bash.

        I don't know what the expected correct behavior here is, so I cannot
        tell if this is a bug or not.  Filing one just in case.

        What strikes me as really odd is the fact that sh is raising the
        error when the function f returns, not when var is assigned to.
        Just see above for the test case and the observed behavior.
        Don't know if there is anything to fix...


Home | Main Index | Thread Index | Old Index