-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Even with 'typeset'? I thought 'typeset' made a local variable no
matter what?
Just curious:
Why the difference between using 'function name' and using 'name()'?
I can understand making new behavior for the new 'function name'
mechanism, and even discouraging the use of the old method, but why go
out of the way to make the behavior of typeset incompatibly different
in the old style 'name()'?
-Kyle
On 11/10/2010 12:25 PM, ольга крыжановская wrote:
> 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:
>>
> 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
>
>>
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users
>>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (MingW32)
iQEcBAEBAgAGBQJM2tfkAAoJEEADRM+bKN5wDmQIAI4OpCnzlmc7CUn1/fsCm38k
wUk01XzfCQpYv5qzlWfch+4xyRay8smHQrEO6T2LGM0J732sBKkojxOb3L2lj2El
oBNGMQw42Y0mqlbc2aXzrnTXvjsL88FFTM5UnFsNocE7YUgXr4b1N7ALDliNbjr1
n26A+kmd6ciq8lr2o3K7npmO5u8N2K+9N+Udml7l5rHcBWvhXkpzOwr4K6NBduyf
87ViLBJIxeFWty6hSTrb8hda1MGjWNxRZCoK9Yw8e115fadM72c3J250dX/AF1JQ
c0Tai5SZGrjTVJ8VruNTMANKuF7PbmNXcHLQtJdyK1fbeQUHqLBMRgyy5R1TDHE=
=Ru1m
-----END PGP SIGNATURE-----
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users