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
, oremacs
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:
- Shell Scripting, Succinctly
- Editing Files in Vi
- Viewing Files and the Nano Editor
- Editing Files with Emacs
Updates
July 6th, 2022 - Made check one accepting of whitespaces and other functional permutations of solutions
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.