Home » Scripting Shell Function

Scripting Shell Function

by Online Tutorials Library

Shell Functions

With the help of functions, overall functionality of a function can be divided into smaller or logical parts, which can be called to perform their task. It helps us to check our program part by part. We can reuse the function where ever we want.

To create a function

Syntax:

You will call your function with their function name.

Example:

Linux Shell function 1

Look at the above snapshot, we have created a function Welcome. We have called it in the above script.

Linux Shell function 2

Look at the above snapshot, on executing the above script, function Welcome is called.


Passing Parameters

You can pass one or more parameters in a function. Parameters will be defined as $1, $2 and so on.

Linux Shell function 3

Look at the above snapshot, $1 is a parameter passed to the function.

Linux Shell function 4

Look at the above snapshot, script produces the above output.

Next TopicSS Case

You may also like