Janis Papanagnou:
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.

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:

   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

Reply via email to