> > Something like typeset would be an advantage, as you say, if one
> > could activate it from the environment, as the OP tried to achieve.
>
> I think it is easy to solve.
Yes, I think so, too; you can write program code to achieve that.
>
> > Even worse, typeset -ft seems to work only on functions already
> > defined, so that you cannot just add it at conveniently at the top
> > of the script, rather you have to put that code after the function
> > definition and before you use the function; so most inconvenient
> > (without further hacks).
>
> It's awkward, but I think the gist that I put up solves that. You don't
> even have to put the typeset -tf in your own code.
>
> There is a simple hack:
Sure, but I think that turning on trace for the whole code (including,
or rather _not excluding_, functions) should not make it necessary to
explicitly code that. YMMV.
Moreover, if I read the POSIX document WRT set -x
"The shell shall write to standard error a trace for each command
after it expands the command and before it executes it."
I am not even sure the ksh behaviour is compliant.
DGK's comment is true as well; in practice we want some control to
exclude or include some functions. (Ksh specific discipline functions
is not exactly the way I'd have expected that to be achieved, though.)
>
> function f1 { : ; } && typeset -tf f1
>
> The typeset -tf will persist when f1 is redefined.
> Current typeset behaviour (and tracef) will catch typos.
>
> Cheers,
> Henk
>
> https://gist.github.com/abafff7c55190bc0bf83 :
>
> foo.sh
>
> # foo.sh - demonstrate the use of adding the option -X flist to a script
> #
> #
> . tracer.sh
> function f1 { echo f1; }
> function f2 { echo f2; }
>
> function main {
> f1
> f2
> }
>
> while getopts X: c;do
> case $c in (X) tracef $OPTARG ;; esac
> done || exit
> shift $((OPTIND-1))
>
> main $@
>
> results.txt #
>
> # Shows the result of calling foo.sh with the -X option
> # matched functions are traced, missing functions are ignored
> # but generate a warning
> #
> HQ:/home/Henk/code/shelltrace 770 $ ksh foo.sh -X f1,f3
> tracef: cannot trace function f3
> [2]+ echo f1
> f1
> f2
>
> HQ:/home/Henk/code/shelltrace 771 $ ksh foo.sh -X f1,f2
> [2]+ echo f1
> f1
> [3]+ echo f2
> f2
>
> HQ:/home/Henk/code/shelltrace 772 $ ksh foo.sh -X f1
> [2]+ echo f1
> f1
> f2
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users