Working with Functions in Your Shell Scripts

Lab Steps

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

The hands-on lab is part of this learning path

Ready for the real environment experience?

DifficultyBeginner
Time Limit45m
Students371
Ratings
4.6/5
starstarstarstarstar-half

Description

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

Expected outputs for each lab step is provided in the script comments

The Linux commands and tools referenced in this lab are:

  • Shell Variables
  • Functions
  • Command Exit Statuses
  • exit
  • echo
  • vim, nano, or emacs

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

Prerequisites

Familiarity with basic Linux commands will be beneficial. Refer to the following course to fulfill the prerequisite:

Updates

18th November, 2022 - Updated instructions to improve clarity

About the Author
Students21749
Labs69
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