Practicing Shell Scripting Fundamentals

Lab Steps

lock
Accessing the Amazon Linux 2 Terminal
lock
Modifying Your Lab Shell Script
lock
Declaring and Using Shell Variables
lock
Incorporating Tests with Conditional Statements
lock
Looping Through Command Line Arguments

The hands-on lab is part of this learning path

Ready for the real environment experience?

DifficultyBeginner
Time Limit45m
Students1308
Ratings
3/5
starstarstarstar-borderstar-border

Description

Shell scripts contain a series of commands that are executed by an interpreter. Shell scripts are easy to use and can help developers automate frequently performed operations and run sequences of commands as a single command. Sharing your scripts with team members is also possible due to the portable nature of these scripts.

In this lab, you will use fundamental shell scripting commands and tools to write a shell script. The commands used in this lab have been covered in the Shell Scripting, Succinctly course. References to the specific lessons of the course will be provided throughout the lab steps.

Expected outputs for each lab step are provided in the script comments.

The Linux commands and tools referenced in this lab are:

  • Shell Variables
  • Command Line Arguments: $1, $@
  • Test Cases: []
  • File Operators: -s, -e
  • Conditional Statements: if, elif, else
  • For Loops: for, do
  • echo
  • vim, nano, or emacs

Learning Objectives

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

  • Declare and utilize variables in a shell script
  • Combine tests with if/else statements to run conditional commands
  • Iterate through command-line arguments with a for loop

Intended Audience

  • Those beginning to work with Linux
  • Those seeking practice with basic shell scripting
  • Software Engineers
  • DevOps Engineers

Prerequisites

Familiarity with basic shell scripting and working with a Linux code editor will be beneficial. Refer to the following courses to fulfill the prerequisite:

Updates

July 6th, 2022 - Made check one accepting of whitespaces and other functional permutations of solutions

About the Author
Students22906
Labs74
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