hands-on lab

Working with Exit Statuses in Your Shell Scripts

Difficulty: Beginner
Duration: Up to 45 minutes
Students: 896
Rating: 4.1/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

Exit statuses and return codes in a shell script offer an effective way of communicating the results of Linux commands and allow for dynamic decision making. Actions based on command exit statuses shape the decision tree within your shell script, while defining accurate exit codes and messaging can make your shell script easier to use by other developers.

In this lab, you will utilize Linux command exit statuses and return codes in a shell script. The commands used in this lab have been covered in the Using Exit Statuses and Return Codes in Your 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
  • Conditional Statements (if, else)
  • Logical Operators (&&, ||)
  • Command Exit Statuses
  • exit
  • echo
  • vim, nano, or emacs

Learning Objectives

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

  • Return specific exit statuses in your own shell scripts
  • Utilize the exit status of a Linux command
  • Make decisions using command exit statuses

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:

Covered topics

Lab steps

Accessing the Amazon Linux 2 Terminal
Modifying Your Lab Shell Script
Defining Shell Script Exit Statuses
Accessing Shell Script Exit Statuses
Making Decisions with Exit Statuses