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
>Organization:
        
>Environment:
        
        
System: NetBSD netbsd.meroh.net 6.99.17 NetBSD 6.99.17 (GENERIC) #0: Sat Feb 23 
07:37:14 EST 2013 
jmmv%netbsd.meroh.net@localhost:/home/jmmv/os/merge/amd64/obj/home/jmmv/os/merge/src/sys/arch/amd64/compile/GENERIC
 amd64
Architecture: x86_64
Machine: amd64
>Description:
        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"
f
echo "after calling f"
-----

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

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

        And with /bin/ksh:

-----
$ ksh ~/test.sh
before calling f
before setting var
/home/jmmv/test.sh[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.
>How-To-Repeat:
        Just see above for the test case and the observed behavior.
>Fix:
        Don't know if there is anything to fix...

>Unformatted:
        
        


Home | Main Index | Thread Index | Old Index