cc: [email protected]
Subject: Re: [ast-developers] $0 in posix function changed to the name of the
function (93t+ 2009-01-20 -> 93t+ 2010-06-21)
--------
> Hi,
>
> I've a report of a regression for ksh scripts like this:
>
> ------------------------------------------------------------------
> #! /usr/bin/ksh
>
> func1()
> {
> print "func1's \$0 = $0 ; \$* = $*"
> }
>
> function func2
> {
> func1 "$*"
> print "func2's \$0 = $0 ; \$* = $*"
> }
>
> func2 "$*"
> print "main's \$0 = $0 ; \$* = $*"
> ------------------------------------------------------------------
>
> for ksh 93t+ 2010-06-21 the broken output is like this
>
> boole:/ # ksh tmp/x 1 2 3
> func1's $0 = func1 ; $* = 1 2 3 <==== $0 here should be
> func2's $0 = func2 ; $* = 1 2 3
> main's $0 = tmp/x ; $* = 1 2 3
>
> whereas for ksh 93t+ 2009-01-20 the correct output is
>
> boole:/ # echo ${KSH_VERSION}
> Version JM 93t+ 2009-01-20
> boole:/ # ksh tmp/x 1 2 3
> func1's $0 = func2 ; $* = 1 2 3
> func2's $0 = func2 ; $* = 1 2 3
> main's $0 = tmp/x ; $* = 1 2 3
>
> please note the first line is different. One comment from
> the report:
>
> | > My question is: is this a problem, please read my comment #1
> | > AFAICS this is the intended behaviour.
> |
> | Yes, this is a problem for GPFS internal tracing of function calls in shell
> | scripts. Because of this bug, the trace data does not show the correct
> | function name which called the posix TRACE function. This makes it very
> | difficult to debug a problem.
> |
> | The behaviors of the posix function are mentioned in chapter 4 of Learning
> the
> | Korn Shell, 2nd Edition book.
> |
> | POSIX functions
> |
> | As mentioned earlier, functions defined using the POSIX syntax obey POSIX
> | semantics and not Korn shell semantics:
> |
> | functname () {
> | shell commands}
> |
> | The best way to understand this is to think of a POSIX function as being
> like
> a
> | dot script. Actions within the body of the function affect all the state of
> th
> e
> | current script. In contrast, Korn shell functions have much less shared
> state
> | with the parent shell, although they are not identical to totally separate
> | scripts.
> |
> | The technical details follow; they include information that we haven't
> covered
> | yet. So come back and reread this section after you've learned about the
> | typeset command in Chapter 6 and about traps in Chapter 8.
> |
> | * POSIX functions share variables with the parent script. Korn shell
> | functions can have their own local variables.
> |
> | * POSIX functions share traps with the parent script. Korn shell functions
> | can have their own local traps.
> |
> | * POSIX functions cannot be recursive (call themselves).[5] Korn shell
> | functions can.
> |
> | [5] This is a restriction imposed by the Korn shell, not by the POSIX
> | standard.
> |
> | * When a POSIX function is run, $0 is not changed to the name of the
> | function.
>
>
> Werner
>
This is a bug since the POSIX standard says that $0 should not change.
I will fix this in ksh93u+. ksh93u is the most recent official ksh93.
However, POSIX function can be recursive in Korn shell, for example
foo()
{
echo name=$0 "$@"
if [[ $1 ]]
then shift
foo "$@"
fi
}
foo "$@"
David Korn
[email protected]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers