The Wayback Machine - https://web.archive.org/web/20240223051840/https://www.geeksforgeeks.org/function-command-in-linux-with-examples/
Open In App
Related Articles

function command in Linux with examples

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The function is a command in Linux that is used to create functions or methods. It is used to perform a specific task or a set of instructions. It allows users to create shortcuts for lengthy tasks making the command-line experience more efficient and convenient. 

The function can be created in the user’s current shell session or saved in the shell startup file to make them available every time a new shell session is initiated

Syntax of function and its usage

1. Using function keyword

A function in Linux can be declared by using the keyword function before the name of the function. Different statements can be separated by a semicolon or a new line. 

SYNTAX: 

function name { COMMANDS ; }
function name { COMMANDS ; }

function name { COMMANDS ; }

2. Using parenthesis

A function can also be declared by using parenthesis after the name of the function. Different statements can be separated by a semicolon or a new line. 

SYNTAX:

name () { COMMANDS ; }
name () { COMMANDS ; }

name () { COMMANDS ; }

3.Parameterised function 

Parameterised function 

Parameterised function 

$1 will displays the first argument that will be sent and $2 will display the second ans so on… 

4.help function

It displays helpful information. 

help function

help function

Conclusion

In this article we have discussed the function command in Linux and how to use it. We need to experiment and explore the various possibilities with the function command. Overall, we can say that with practice, we will become proficient in utilizing functions to simplify and expedite our daily Linux tasks. 


Last Updated : 05 Jul, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads