Operating System - HP-UX
1748123 Members
3428 Online
108758 Solutions
New Discussion юеВ

Calling Function in another Script

 
joseni
Occasional Contributor

Calling Function in another Script

Hi,
I have a script file with me called "first.sh" and contains one function called "ValidateDOB" in it. I want to call this function from another script file "second.sh".

Can you pleaase help me to call this ..
3 REPLIES 3
Philip Gunter
Respected Contributor

Re: Calling Function in another Script

Hi Joseni,

to do this you want to "source" first.sh from second.sh this is done using a period "."

Eg
#!/bin/sh
# this is second.sh

# Source first.sh
. /path/to/first.sh

# do stuff here
ValidateDOB


Cheers,
Philip.

Dennis Handly
Acclaimed Contributor

Re: Calling Function in another Script

Beside sourcing the file, you can also set FPATH to the directory where each function is in a file with the same name.
Arturo Galbiati
Esteemed Contributor

Re: Calling Function in another Script

Hi,
bext solutin is to isolate teh function into a file and recall it by two script.
i.e.:


script1
....
. ValidateDOB.ksh
ValidateDOB
...
...

script2
....
. ValidateDOB.ksh
ValidateDOB
...

in alternative you can use the FPATCH variable.

HTH,
Art