What Is Unix Shell Function?

What Is Unix Shell Function?
Contents

Functions enable you to break down the overall functionality of a script into smaller, logical subsections, which can then be called upon to perform their individual tasks when needed. … Using functions to perform repetitive tasks is an excellent way to create code reuse.

What is shell function?

Shell functions are a way to group commands for later execution using a single name for the group. They are executed just like a “regular” command. … If the function reserved word is supplied, the parentheses are optional. The body of the function is the compound command compound-command (see Compound Commands).

How do you create a shell function?

Creating Functions

The name of your function is function_name, and that’s what you will use to call it from elsewhere in your scripts. The function name must be followed by parentheses, followed by a list of commands enclosed within braces.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.