This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes Calling functions of one script in to the other Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Calling functions of one script in to the other" Watch "Calling functions of one script in to the other" New topic
Author

Calling functions of one script in to the other

Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 117
Hi all,

I am using Bash shell. I want to call function in one shell script into the other.
I know I can reference one shell script into the other using '.' operator or using 'source'

My shell script applib.sh(containing function) is using "getopts" and throws usage followed by exit 1 when called without arguments.
So when I include this script(applib.sh) within another script say, "uselib.sh", using '.' or 'source' and try to run "uselib.sh"
it executes "applib.sh", and exits.

So I wanted to know is there any other way where in I can call function from "applib.sh".
OR let me know if I need to follow some standard

like I need to keep all functions in separate file and make use of them including this file in my scripts ?


Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

If you're running one of the Red Hat flavors such as Fedora, just look in the /etc/init.d directory. A lot of their scripts do what you want. It allows them to have common code for displaying start/stop messages, daemonizing, and various networking functions.

You may find similar functionality in the non-RedHat distros such as Debian and Ubuntu, but I haven't spent that much time in their initscripts to be able to say for sure.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling functions of one script in to the other
 
Similar Threads
Using java Script with jsp
Script to Find & Remove text in multiple files.
To call a javascript function using shell script
problem with goto ,blocks
how can i call a shell script method in other program