0% found this document useful (0 votes)
26 views2 pages

How to Define and Use Shell Functions

A function in shell scripting is a series of commands designed to perform a specific task, defined using a specific syntax. The syntax includes the function name, commands, and a return statement to terminate the function. An example provided shows how to create and execute a function named SayHello that greets the user.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

How to Define and Use Shell Functions

A function in shell scripting is a series of commands designed to perform a specific task, defined using a specific syntax. The syntax includes the function name, commands, and a return statement to terminate the function. An example provided shows how to create and execute a function named SayHello that greets the user.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Function is series of instruction/commands.

Function performs
particular activity in shell i.e. it had specific work to do or simply say
task. To define function use following syntax:

Syntax:
function-name ( )
{ command1
command2 ..... ...
command N
return }

Where function-name is name of the function, that executes series of


commands.
A return statement will terminate the function.
Example:
Type SayHello() at $ prompt as follows

$ SayHello()
{
echo "Hello $LOGNAME, Have nice computing"
return
}

To execute this SayHello() function just type it name as follows:

$ SayHello

You might also like