Bash script modular functions

Hello

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 functions.sh 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
jculkincys
LVL 2
jculkincysAsked:
Who is Participating?
 
xDamoxCommented:
Hi,

Simply test the following:

source functions_file

heres an full example:

test.sh
------------------
#!/bin/bash

source test2.sh

hello;

----------------

test2.sh
----------------
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. test.sh
0
 
jculkincysAuthor Commented:
I like it

Thank you kindly

P.S. are getting sick of answering my simple questions? haha
0
 
xDamoxCommented:
hehe Never :) I enjoy helping others
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.