Member-only story
Linux — Shell Scripting/Functions
The purpose of this hands-on training is to teach you how to use functions in shell.
Learning Outcomes
At the end of this hands-on training, you will be able to;
- explain and use functions in the shell.
Outline
- Part 1 — Creating Functions
- Part 2 — Passing Arguments to Functions
- Part 3 — Returning Values from Functions
- Part 4 — Nested Functions
- Part 5 — Variables Scope
Part 1 — Creating Functions
- A Bash function is a piece of code that only runs when it is called. Functions enable you to reuse code. We can call the functions numerous times.
- Create a folder and name it
functions.
mkdir functions && cd functions- It is pretty easy to declare and call a function. Create a
scriptfile namedfunctions.sh.
#!/bin/bashWelcome () {
echo "Welcome to Linux Lessons"
}Welcome
- Make the script executable and execute it.
chmod +x functions.sh
./functions.sh




