Computing.Net > Forums > Unix > Functions in korn shell

Functions in korn shell

Reply to Message Icon

Original Message
Name: elpico
Date: May 14, 2003 at 07:22:44 Pacific
Subject: Functions in korn shell
OS: Unix solaris
CPU/Ram: 256
Comment:

Hi all,

I'm getting problems accessing functions in ksh from other ksh files --- is there a way to do this? And does anyone have any suggestions to pass parameters from one script to another that has functions in it?

Basically I'm trying to avoid having tons of the same functions in every script I create.

A way I was trying to get around this was that inside script1 I would call script2 and pass a paramter to it -- Then inside script2 pick up the argument and test it using a case ---- but this gets a bit messy too...

Any suggestions/advice?
Thanks again,
elpico.


Report Offensive Message For Removal

Response Number 1
Name: nails
Date: May 14, 2003 at 14:28:38 Pacific
Subject: Functions in korn shell
Reply: (edit)

Hi:

The Korn shell automatically loads a function the first time it's called provided the function resides in a directory in the shell variable FPATH (the format of FPATH is the same as PATH), and the command of the
same name can not be found, or the function is typeset with the -u option:

typeset -fu

an alias for "typeset -fu" is autoload.

Regards,


Nails


Report Offensive Follow Up For Removal

Response Number 2
Name: nails
Date: May 14, 2003 at 14:29:46 Pacific
Subject: Functions in korn shell
Reply: (edit)

sorry, the arrow keys were wiped out:

typeset -fu yourfunctionname



Report Offensive Follow Up For Removal

Response Number 3
Name: WilliamRobertson
Date: May 14, 2003 at 17:09:04 Pacific
Subject: Functions in korn shell
Reply: (edit)

You can also explicitly source the script that contains the function definitions, the same way you'd pick up variable definitions e.g:

. /somepath/myfunctions.ksh


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Functions in korn shell

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software