hands-on lab

Working with Functions in Your Shell Scripts

Difficulty: Beginner
Duration: Up to 45 minutes
Students: 1,181
Rating: 4/5
On average, students complete this lab in25m
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.

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

Covered topics

Hands-on Lab UUID

Lab steps

0 of 3 steps completed.Use arrow keys to navigate between steps. Press Enter to go to a step if available.
  1. Accessing the Amazon Linux 2 Terminal
  2. Defining Functions in Your Shell Scripts
  3. Accessing Local Variables and Function Parameters