General
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Function in another Script

 
Highlighted
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
Highlighted
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.

Highlighted
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.
Highlighted
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