Working with Functions in Your Shell Scripts

Lab Steps

Accessing the Amazon Linux 2 Terminal
Modifying Your Lab Shell Script
Defining Functions in Your Shell Scripts
Accessing Local Variables and Function Parameters

The hands-on lab is part of this learning path

This lab is currently under maintenance and unavailable. We're actively working to resolve this issue and we apologize for any inconvenience.

Ready for the real environment experience?

Time Limit45m


Functions allow developers to reuse code, reduce the amount of code they need to write, and improve their ability to maintain their scripts. With the use of variables and parameters, functions can be written once and reused to handle dynamic data in your scripts.

In this lab, you will utilize functions, parameters, and variables in a shell script. The commands used in this lab have are covered in the Functions in Scripts course. References to the specific lessons will be provided throughout the lab steps.

The expected outputs for each lab step are provided as comments in the lab script file.

Learning Objectives

Upon completion of this lab, you will be able to:

  • Create a function in a shell script
  • Access the positional parameters passed into a function
  • Define global and local variables

Intended Audience

  • Those beginning to work with Linux
  • Those looking to gain experience with basic shell scripting
  • Software Engineers
  • DevOps Engineers


You should be familiar with the following shell scripting features before attempting this lab:

  • Command Exit Statuses
  • Conditional Statements (if/else)
  • Logical Operators (&&/||)
  • Shell Variables
  • Vim, Nano, or Emacs


Refer to the following courses to fulfill the prerequisite:

About the Author
Learning paths3

Jun is a Cloud Labs Developer with previous experience as a Software Engineer and Cloud Developer. He holds the AWS Certified Solutions Architect and DevOps Engineer Professional certifications. He also holds the AWS Certified Solutions Architect, Developer, and SysOps Administrator Associate certifications. 

Jun is focused on giving back to the growing cloud community by sharing his knowledge and experience with students and creating engaging content. 

Covered Topics