LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Add user defined function in main library (https://www.linuxquestions.org/questions/linux-newbie-8/add-user-defined-function-in-main-library-443734/)

reach2tripplek 05-11-2006 04:32 AM

Add user defined function in main library
 
Hi friends
I have wrote a chk_err function which checks for error in a shell script logfile.sh. I want to use this function in other shell script but without writing the function again instead I just want to call this function there.
Can anybody help me out how can i do that.The prob is how i will add user defined function in main library so that i can access it everywhere


Thanks
Kamal

ioerror 05-11-2006 07:47 AM

You can source another file in a script with

Quote:

. /path/to/script
or

Quote:

source /path/to/script
They are slightly different in that . won't look in the current directory so '. foo' won't work but '. ./foo' will, as will 'source foo'.

cs-cam 05-11-2006 09:15 AM

To expand slightly on the above, sourcing a file in another will execute it inside the current script and thus make it's variables and functions available. Note that one, it will run the code.

Code:

source check_err.sh

some_func_from_chk_err()



All times are GMT -5. The time now is 12:01 PM.