Last Updated : 05 Jul, 2023
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 keywordA 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 ; } 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 ; } 3.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 functionIt displays helpful information.
help function ConclusionIn 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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4