• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Himai Minh
  • Carey Brown
  • Frits Walraven

Calling functions of one script in to the other

Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
Saloon Keeper
Posts: 23929
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic