LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-11-2006, 04:32 AM   #1
reach2tripplek
LQ Newbie
 
Registered: May 2006
Posts: 2

Rep: Reputation: 0
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
 
Old 05-11-2006, 07:47 AM   #2
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
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'.
 
Old 05-11-2006, 09:15 AM   #3
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
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()
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
list library function of a shared library .so powah Linux - General 7 10-25-2011 04:47 AM
user defined function in kernel vishalbutte Programming 4 02-07-2006 06:01 AM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
what is the function library of the basic graphics library in rethat9.0? zerwolve Red Hat 0 04-29-2004 09:18 PM
C++: How to use a namespace in a user-defined library? Gethyn Programming 9 08-15-2003 05:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration