POSIX does AFAIK not define typeset. I see it now this way: 1. typeset creates a variable local to a function 2. The -x flag makes this variable as 'exported' if an external command is called 3. Another function must not see a variable local to another function, even if the export flag is set for this variable
Conclusion: The ksh93 behaviour is correct, bash4.0's behaviour is not. Olga On Sat, Nov 6, 2010 at 3:18 AM, Mostyn Lewis <[email protected]> wrote: > I don't usually carp on this list, especially to the author but I > respectively submit that reading the man page says typeset -x is equivalent > to export and > there is no reference to an exclusion to that if it's in a function. Yes, > it's said that typeset renders local scope but in the logical English > typeset -x seems > to be an exception. Bash and zsh accomplish this exception. What does POSIX > say or does it not? > > Regards, > Mostyn > > On 11/05/2010 07:09 AM, David Korn wrote: >> >> Subject: Re: [ast-users] Is it correct that exporting function-local >> variable causes the variable not to be exported if the function exporting >> the local variable calls another function and this function calls an >> external command ? >> -------- >> >>> ksh93 -c 'function y { ksh -c "print \$ex" ; } ; function x { >>> typeset -x ex ; for ex in "foo" "bar" ; do export ex ; y ; done ; } ; >>> x' >>> >> >> With ksh93, variables are statically scoped whereas they are >> dynamically scoped in ksh88. >> >> Thus, since you have >> typeset -x ex >> in function x, this creates a local variable in x that will not >> be seen in function y. >> >> However, if you omit the typeset -x ex in function x and only >> have export ex, then ex will be a global variable that is >> exported and will therefore be known in function y. >> >> Thus, this behavior is correct. >> >> David Korn >> [email protected] >> _______________________________________________ >> ast-users mailing list >> [email protected] >> https://mailman.research.att.com/mailman/listinfo/ast-users >> > > _______________________________________________ > 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
