On Fri, Jan 13, 2017 at 10:56:51AM +0100, Otto Moerbeek wrote: > On Fri, Jan 13, 2017 at 10:20:19AM +0100, Otto Moerbeek wrote: > > > On Fri, Jan 13, 2017 at 09:51:51AM +0100, Otto Moerbeek wrote: > > > > > On Fri, Jan 13, 2017 at 09:46:54AM +0100, Anton Lindqvist wrote: > > > > > > > Consider the following script which calculates the sum of the first N > > > > integers recursively: > > > > > > > > $ cat >sum.sh <<! > > > > sum() { > > > > [ $1 -eq 0 ] && echo $2 || sum $(($1 - 1)) $(($2 + $1)) > > > > } > > > > > > > > sum 5 > > > > ! > > > > > > > > Executing the script with the x option gives the following output: > > > > > > > > $ sh -x sum.sh > > > > + sum 5 > > > > 15 > > > > > > > > I would expect the recursive calls to be traced, similar to how GNU > > > > bash/sh behaves. With the patch below applied the output is as expected: > > > > > > > > $ sh -x sum.sh > > > > + sum 5 > > > > + [ 5 -eq 0 ] > > > > + sum 4 5 > > > > + [ 4 -eq 0 ] > > > > + sum 3 9 > > > > + [ 3 -eq 0 ] > > > > + sum 2 12 > > > > + [ 2 -eq 0 ] > > > > + sum 1 14 > > > > + [ 1 -eq 0 ] > > > > + sum 0 15 > > > > + [ 0 -eq 0 ] > > > > + echo 15 > > > > 15 > > > > > > > > The patch make sure to assigns the TRACE flag to every user-defined > > > > function if the x option is present. The piece of code that led me to > > > > this: > > > > > > > > $ sed -n 606,607p /usr/src/bin/ksh/exec.c > > > > old_xflag = Flag(FXTRACE); > > > > Flag(FXTRACE) = tp->flag & TRACE ? true : false; > > > > > > Hmmm, > > > > > > afaik -x has always been local to a function in ksh-like shells. > > > To enable tracing within function call set -x in the fucntion te be > > > traced. > > > > or set the trace attribute for a specific function: > > > > typeset -ft sum
Thanks, didn't know. > Hmm, I see now that my memory is false, ksh93 (available as port) does > trace into functions. Still, I'm undecided if we want to change our > ksh. Any thoughts from others on changing the defaults?