Bash script modular functions

Posted on 2006-04-20
Last Modified: 2007-12-19

I am trying to "include" fucntions from a files in my bash scripts similar to the way PHP does it.

For example if I have a file called which includes commonly used functions, I want to include that in every bash script.

What I want to do is similar to php's include function. Is this possible?

Thanks for any and all help
Question by:jculkincys
    LVL 16

    Accepted Solution


    Simply test the following:

    source functions_file

    heres an full example:



    function hello() {
            echo "Hello World";

    you dont need to include the #!/bin/bash header in your fuctions because its already included
    in your main file e.g.
    LVL 2

    Author Comment

    I like it

    Thank you kindly

    P.S. are getting sick of answering my simple questions? haha
    LVL 16

    Expert Comment

    hehe Never :) I enjoy helping others

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
    Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now