Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

unexpected unmodified variable




func2 ()
{
count=2
echo from func2: $count
}

func1 ()
{
local count=1
func2
echo from func1: $count
count=1
var=$( func2 )
echo from func1: $count
echo var is: $var
}

$ func1
from func2: 2
from func1: 2
from func1: 1
var is: from func2: 2

... This catches me by surprise; when " var =$( func2 ) " happens I'm expecting 'func2' to do everything it does including reset 'count' to '2'.  Why doesn't it, and is there any way to solve that?  Hacking around:

func1 ()
{
local count=1
func2 > /dev/null

func2

}

... performs as I'm wanting it to but it's a bit disgusting.









Messages sorted by: Reverse Date, Date, Thread, Author