Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling functions of one script in to the other

 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic