Help with shell scripts ??? 
Author Message
 Help with shell scripts ???

I need to know if there is any way to create and call libraries with
user defined functions from one script.

I work with unix HP-UX10

I make many shell scripts and I have several functions pre-defined that
I use, but I have to include them in all the scripts i write, and want
to know if there is a way to create a library that i can call from those
scripts.

Luis Filipe Reis



Tue, 07 Mar 2000 03:00:00 GMT  
 Help with shell scripts ???

Quote:

> I need to know if there is any way to create and call libraries with
> user defined functions from one script.

> I work with unix HP-UX10

> I make many shell scripts and I have several functions pre-defined
> that
> I use, but I have to include them in all the scripts i write, and want

> to know if there is a way to create a library that i can call from
> those
> scripts.

> Luis Filipe Reis

 The korn shell supports "autoload" functions. You basically set up a
directory
with all of your pre-defined functions (1 per file, with the same name
as the
function). Set the environment variable FPATH to point to your library
directory.
Now, whenever you want to use one of the library functions, just put

autoload function_name
i.e. autoload string_parse

at the start of your shell. The shell interpreter will look through
FPATH for
a file named "string_parse" with the function "string_parse in it.

I hope this is what you were after.

--

Quote:
>>>---------------------------------<<<

   Joel Friedman (N-Tier Consultant)

Quote:
>>>---------------------------------<<<



Wed, 08 Mar 2000 03:00:00 GMT  
 Help with shell scripts ???


: > I need to know if there is any way to create and call libraries with
: > user defined functions from one script.
: >
: > I work with unix HP-UX10
: >
: > I make many shell scripts and I have several functions pre-defined
: > that
: > I use, but I have to include them in all the scripts i write, and want
: >
: > to know if there is a way to create a library that i can call from
: > those
: > scripts.
: >
: > Luis Filipe Reis

:  The korn shell supports "autoload" functions. You basically set up a
: directory
: with all of your pre-defined functions (1 per file, with the same name
: as the
: function). Set the environment variable FPATH to point to your library
: directory.
: Now, whenever you want to use one of the library functions, just put

: autoload function_name
: i.e. autoload string_parse

: at the start of your shell. The shell interpreter will look through
: FPATH for
: a file named "string_parse" with the function "string_parse in it.

: I hope this is what you were after.

: --
: >>>---------------------------------<<<
:    Joel Friedman (N-Tier Consultant)

: >>>---------------------------------<<<

autoload is only necessary where there is a conflict between the
function name and the name of a built-in or command from the
PATH;  for instance,  if you wanted to overload ll.

--
Dan Mercer

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



Fri, 10 Mar 2000 03:00:00 GMT  
 Help with shell scripts ???

Quote:
> I make many shell scripts and I have several functions pre-defined that
> I use, but I have to include them in all the scripts i write, and want
> to know if there is a way to create a library that i can call from those
> scripts.

> Luis Filipe Reis

Well in my opinion you can use the '.' statement of the shell itself.
For instance if your library is named  shlib.inc  (for SHell LIBrary to
INClude)
then your new shell script could start like

#!/bin/sh
. shlib.inc

(There is a space between the dor and the library name!)
This will include the library in your shell script automatically.
Hope that helps.

Giso



Sat, 08 Apr 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help with shell scripts

2. HELP: sourcing shell scripts or functions to change env variables

3. Scheme Shell: Shell Scripting for the 90's

4. Scheme Shell: Shell Scripting for the 90's

5. Scheme Shell: Shell Scripting for the 90's

6. Scheme Shell: Shell Scripting for the 90's

7. Scheme Shell: Shell Scripting for the 90's

8. help for newbie: way to get the value of an awk variable in a shell script

9. Help in converting simple shell script.

10. expect script with shell script

11. Set expect script variables via a korn shell script

12. converting korn shell scripts to tcl scripts

 

 
Powered by phpBB® Forum Software