hands-on lab

Working with While Loops in Your Shell Scripts

Difficulty: Beginner
Duration: Up to 45 minutes
Students: 668
Rating: 3.6/5
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 while loops in two Linux shell scripts. The commands used in this lab have been covered in the While Loops course. References to the specific lessons of the course 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:

  • Read each line of a file using a while loop
  • Run commands a specified number of times using a while loop

Intended Audience

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

Prerequisites

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

  • While Loops
  • Grep
  • Shell Variables
  • Vim, Nano, or Emacs

Refer to the following courses to fulfill the prerequisite:

Environment before

Environment after

Covered topics

Lab steps

Accessing the Amazon Linux 2 Terminal
Modifying Your Lab Shell Script
Reading Files with a While Loop
Looping Through a Given Index