Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Command Line Fundamentals

You're reading from   Command Line Fundamentals Learn to use the Unix command-line tools and Bash shell scripting

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher
ISBN-13 9781789807769
Length 314 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Vivek Nagarajan Vivek Nagarajan
Author Profile Icon Vivek Nagarajan
Vivek Nagarajan
Arrow right icon
View More author details
Toc

Shell Functions

Shell functions are very similar to functions in most programming languages. They allow us to group commands into a unit and provide them with a name. We can later execute the commands in the function by invoking its name, just like any other command. In essence, shell functions let us define our own commands that are indistinguishable from the inbuilt ones.

Function Definition

Functions can be created with this basic syntax:

function name() 
{
  COMMANDS
}

Here, COMMANDS may be one or more commands, lists, or pipelines, and represent the function body. The braces must be separated from the rest of the syntax with whitespace, typically with newlines. When the function name is typed on the command line as if it were a command, we say that the function has been invoked or called and the commands in the function body are executed.

Note

The function keyword can be omitted when defining a function—it is optional, according to the syntax...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime