func() {...;} style functions do not allow function local variables in
ksh93, all variables declared that way are global. You need to declare
the function with function func {...;} to get local variables for
functions, this works for ksh88 and ksh93.Olga On Wed, Nov 10, 2010 at 6:16 PM, Kyle McDonald <[email protected]> wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Or am I doing (or expecting?) something wrong? > > I've boiled my script down quite a bit to isolate the behavior. The > code is at the bottom. > > Ignore the output for LIST in the this, I was also trying to isolate a > problem with that not behaving the way I expect, but while isolating > the proble with TYPE, I actually eliminated the problem with LIST. If > I can reproduce the LIST problem maybe I'll send another question later. > > This is the output I get with the OpenSolaris ksh93: > > [kmcdon...@galileo] 297> ./Test1.sh > :TYPE=None :LIST=Zero: > Main :TYPE=None :LIST=Zero: > Func1 :TYPE=None :LIST=Zero: > Func1 :TYPE=RIGHT :LIST=Zero: > Func2 :TYPE=RIGHT :LIST=Zero: > Func2 :TYPE=WRONG!:LIST=Zero One: > Func2 :TYPE=WRONG!:LIST=Zero One: > Func2 :TYPE=WRONG!:LIST=Zero One Two: > Func1 :TYPE=WRONG!:LIST=Zero One Two: > Main :TYPE=WRONG!:LIST=Zero One Two: > :TYPE=WRONG!:LIST=Zero One Two: > > However I expected to see what bash and /bin/ksh (88??) give below: > (/export/Install/src/bin) > [kmcdon...@galileo] 298>bash ./Test1.sh > :TYPE=None :LIST=Zero: > Main :TYPE=None :LIST=Zero: > Func1 :TYPE=None :LIST=Zero: > Func1 :TYPE=RIGHT :LIST=Zero: > Func2 :TYPE=RIGHT :LIST=Zero: > Func2 :TYPE=WRONG!:LIST=Zero One: > Func2 :TYPE=RIGHT :LIST=Zero One: > Func2 :TYPE=WRONG!:LIST=Zero One Two: > Func1 :TYPE=RIGHT :LIST=Zero One Two: > Main :TYPE=RIGHT :LIST=Zero One Two: > :TYPE=RIGHT :LIST=Zero One Two: > (/export/Install/src/bin) > [kmcdon...@galileo] 299>ksh ./Test1.sh > :TYPE=None :LIST=Zero: > Main :TYPE=None :LIST=Zero: > Func1 :TYPE=None :LIST=Zero: > Func1 :TYPE=RIGHT :LIST=Zero: > Func2 :TYPE=RIGHT :LIST=Zero: > Func2 :TYPE=WRONG!:LIST=Zero One: > Func2 :TYPE=RIGHT :LIST=Zero One: > Func2 :TYPE=WRONG!:LIST=Zero One Two: > Func1 :TYPE=RIGHT :LIST=Zero One Two: > Main :TYPE=RIGHT :LIST=Zero One Two: > :TYPE=RIGHT :LIST=Zero One Two: > > Here's the code. Shouldn't the 'typeset TYPE' in Func2 make TYPE a > local variable for that function only? I expected it to hide the > global TYPE, but it shouldn't change the global TYPE, should it? > > (/export/Install/src/bin) > [kmcdon...@galileo] 300>cat Test1.sh > #!/bin/ksh93 > TYPE="None " > LIST="Zero" > > Main() > { > echo "Main :TYPE=${TYPE}:LIST=${LIST}:" > Func1 "$...@}" > echo "Main :TYPE=${TYPE}:LIST=${LIST}:" > } > > Func1() > { > echo "Func1 :TYPE=${TYPE}:LIST=${LIST}:" > TYPE="RIGHT " > > echo "Func1 :TYPE=${TYPE}:LIST=${LIST}:" > Func2 One > Func2 Two > echo "Func1 :TYPE=${TYPE}:LIST=${LIST}:" > } > > Func2() > { > echo "Func2 :TYPE=${TYPE}:LIST=${LIST}:" > LIST="${LIST} ${1}" > typeset TYPE="WRONG!" > echo "Func2 :TYPE=${TYPE}:LIST=${LIST}:" > } > > echo " :TYPE=${TYPE}:LIST=${LIST}:" > Main "$@" > echo " :TYPE=${TYPE}:LIST=${LIST}:" > > > Am I nuts? > > Thanks! > > -Kyle > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.14 (MingW32) > > iQEcBAEBAgAGBQJM2tNjAAoJEEADRM+bKN5w3JkIAKfgT4XUKwmkYpEBTIqLFyCw > pwMC2Ok3yeC+n/RvWx9G+9cXjvVEQxY0JbhCBgEIiNNKd5zyrHrPwCdJIloj3m4m > AxME7lwtrK2gzGOtwrCQwdihdaUh9fBGuvY2aG1AecEdJEbfuyt0hA7xIBTCcKXr > ZgmIJjzXj5zSKnhhaBrsaSo0A/y0CJfR5IQvswofAIwpns1U6Z2iy2rynQs+uV74 > 5xDyYyyc/PQaz+UWlSq3ONx1WC7P18jzOjGrnb9qKihQObugxSDkwNiHfVknrkFF > a5B+XaqOn7eskB7ZGTpGpd7kklqGEJtzz6C6aypFr4WPW9zkIT5z342zgzfnLBU= > =+LV5 > -----END PGP SIGNATURE----- > > _______________________________________________ > ast-users mailing list > [email protected] > https://mailman.research.att.com/mailman/listinfo/ast-users > -- , _ _ , { \/`o;====- Olga Kryzhanovska -====;o`\/ } .----'-/`-/ [email protected] \-`\-'----. `'-..-| / http://twitter.com/fleyta \ |-..-'` /\/\ Solaris/BSD//C/C++ programmer /\/\ `--` `--` _______________________________________________ ast-users mailing list [email protected] https://mailman.research.att.com/mailman/listinfo/ast-users
