ksh93 discipline functions

ksh93 discipline functions

Post by Dan Merc » Wed, 10 Nov 1999 04:00:00





> Discipline Functions.

>     Each variable can have zero or more discipline functions
>     associated with it. The shell initially understands the
>     discipline names get, set, and unset but on most systems
>     others can be added at run time via the C programming
>     interface extension provided by the builtin built-in utility.

> I don't quite understand how you'd define a discipline function.
> Anyone?

A get function is used whenever $vname is accessed.  A set function
is invoked anytime vname=value is accessed.  The unset function
is invoked anytime unset vname is invoked.  Here are functions
I use in profiling a shell script:

PROFILE=0

function profile
   {
   # set up profiling
   PROFILE=0
   SECONDS=0
   export PS4='l=$LINENO t=$PROFILE: '
   }

function PROFILE.get
   {
   ((.sh.value = int(1000*SECONDS),SECONDS=0))
   }

Now to profile a patch of code,  I surround it with
set -x and set +x.

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

ksh93 discipline functions

Post by Dan Merc » Wed, 10 Nov 1999 04:00:00







> # > Discipline Functions.
> # >
> # >      Each variable can have zero or more discipline functions
> # >      associated with it. The shell initially understands the
> # >      discipline names get, set, and unset but on most systems
> # >      others can be added at run time via the C programming
> # >      interface extension provided by the builtin built-in utility.
> # >
> # > I don't quite understand how you'd define a discipline function.
> # > Anyone?
> #
> # A get function is used whenever $vname is accessed.  A set function
> # is invoked anytime vname=value is accessed.  The unset function
> # is invoked anytime unset vname is invoked.  Here are functions
> # I use in profiling a shell script:
> #
> # PROFILE=0
> #
> # function profile
> #    {
> #    # set up profiling
> #    PROFILE=0
> #    SECONDS=0
> #    export PS4='l=$LINENO t=$PROFILE: '
> #    }
> #
> # function PROFILE.get
> #    {
> #    ((.sh.value = int(1000*SECONDS),SECONDS=0))
> #    }
> #
> # Now to profile a patch of code,  I surround it with
> # set -x and set +x.

> OK.  Thanks.  The problem was that I thought I could put these
> functions in my FPATH, and then use typeset -fu on them.  That
> wouldn't work for some reason.  When I put them in my .profile, it
> worked fine.

The code above was from an FPATH'ed function called "profile".
To use the FPATH,  you need a function to install the discipline
functions.

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

1. Any way to capture lineno in discipline function

I'm trying to write a Discipline Function for ksh93. And I was wondering if
there was any way to capture the line number of the line which causes the
discipline function to be invoked?  If I code $LINENO in my function it
always returns the line number of the function, not the line number that
invoked the function?

Thanks,
Ken

2. NCSA 1.5a and virtual???

3. ksh93 typeset in function no longer local

4. Can't boot using win98 startup disk

5. ksh93 or Linux alias/function problem?

6. How to restrict people to seeing directory contents

7. arithmetic function with ksh93

8. An iBCS2 question

9. Using $0 inside ksh93 function from ~/.profile

10. Where to place functions in ksh88/ksh93 scripts?

11. function, function...who's got the function?

12. DIP cannot set line discipline!

13. Need (!?!) Info on Line Disciplines