Creating a library of functions in Linux shell script

April 29, 2021

If we want to create our own library of functions, then we can create a script and add all the functions into this script. We can make all the functions from our script available in the current shell by calling source or the period . command.

The procedure to load all functions into the current shell is as follows:

$ country USA

Since the country function is not a part of the shell environment, this command will give an error:

$ .

Or it could display this one:

$ source
$ country USA India Japan

This will execute the country function along with the parameter, USA India Japan.

We can even load a script containing library functions inside another script as follows:

. /../ 

We have called the library function script inside another script. This will define all the functions within the script available in the current script environment.

Related Articles

Calculating and reducing the runtime of a script

In this article, we are going to learn how to calculate and reduce the script’s runtime. A simple time command will help in calculating the execution time.PrerequisitesBesides having a terminal open, make sure you have the necessary scripts present in your...

read more

Lorem ipsum dolor sit amet consectetur


Submit a Comment

Your email address will not be published. Required fields are marked *

fourteen − three =