Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 05-11-2006, 04:32 AM   #1
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 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

Old 05-11-2006, 07:47 AM   #2
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 30
You can source another file in a script with

. /path/to/script

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
Senior Member
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

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.




Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

All times are GMT -5. The time now is 02:37 AM.

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