Operating System - HP-UX
1826312 Members
4395 Online
109692 Solutions
New Discussion

Including file with internal functions within a shell script

 
SOLVED
Go to solution
Rui Vilao
Regular Advisor

Including file with internal functions within a shell script

Greetings,

I am writing a set of administration scripts.
I have already written a “library” of internal functions.

In order to reuse easily the written code in other shell scripts I would like to include it from another file without having to write it in the body of each shell script…

Can this be done?

Any help/suggestion is highly appreciated.

TIA.

Kind Regards,

Rui
"We should never stop learning"_________ rui.vilao@rocketmail.com
3 REPLIES 3
Pete Randall
Outstanding Contributor
Solution

Re: Including file with internal functions within a shell script

If I understand your question, you would just execute the function from within your script:

do this
do something else

#invoke funtion

. function

finish up


Pete

Pete
curt larson_1
Honored Contributor

Re: Including file with internal functions within a shell script

you use the FPATH variable to define where the shell looks for function definitions
renarios
Trusted Contributor

Re: Including file with internal functions within a shell script

Hi Rui,

Try FPATH

FPATH allows a list of function library directory names to be accessed. The shell will search through the directory list until it finds a file that matches the name of the funcion being used.
You can use autoload to declare a function from an external script.
Autoload is an alias for "typeset -fu"

Hope this helps,

Renarios
Nothing is more successfull as failure