Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

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

Calling functions of one script in to the other

Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 118
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 function) is using "getopts" and throws usage followed by exit 1 when called without arguments.
So when I include this script( within another script say, "", using '.' or 'source' and try to run ""
it executes "", and exits.

So I wanted to know is there any other way where in I can call function from "".
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: 17026

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Calling functions of one script in to the other
It's not a secret anymore!