Interstellar Cargo Manifest

ShellBeginner
Practice Now

Introduction

Welcome, space cadet! You're training to become a cargo officer on the interstellar ship "Nebula Nomad." Your first task is to create a simple inventory system for the ship's three cargo bays. You'll use shell arrays to store the inventory and accept a command-line argument to display the contents of a specific cargo bay.

Creating the Cargo Manifest Script

Tasks

  1. Open the existing shell script named cargo_manifest.sh in the /home/labex/project directory.
  2. Complete the script by filling in the missing parts to create and display the ship's cargo inventory.
  3. Run the script with different arguments to display each cargo bay's inventory.

Requirements

  1. The script cargo_manifest.sh is already created in the /home/labex/project directory with a code framework.
  2. Complete the script by:
    • Creating three arrays named forward_bay, midship_bay, and aft_bay.
    • Each array should contain exactly 3 items (strings) representing cargo items.
    • Use the $1 variable to check which cargo bay inventory to display.
    • Display the inventory of the requested cargo bay using echo statements.
  3. The script should accept one argument: either "forward", "midship", or "aft".
  4. If no argument is provided, the script should display: "Please specify a cargo bay: forward, midship, or aft"
  5. If an invalid argument is provided, the script should display: "Invalid cargo bay. Choose forward, midship, or aft."

Example

After completing the script, running it should produce output similar to this:

$ ./cargo_manifest.sh forward
Forward Bay Inventory:
1. Space Suits
2. Oxygen Tanks
3. Repair Kits

$ ./cargo_manifest.sh midship
Midship Bay Inventory:
1. Food Supplies
2. Water Containers
3. Medical Equipment

$ ./cargo_manifest.sh aft
Aft Bay Inventory:
1. Spare Parts
2. Fuel Cells
3. Scientific Instruments

$ ./cargo_manifest.sh
Please specify a cargo bay: forward, midship, or aft

$ ./cargo_manifest.sh engine
Invalid cargo bay. Choose forward, midship, or aft.

The script's strings must reference the examples and remain unchanged to prevent test failures.

✨ Check Solution and Practice

Summary

In this challenge, you've created a simple inventory management system using shell arrays and basic command-line argument handling. You've practiced defining arrays, accessing array elements, and using if statements to process command-line inputs. These fundamental skills are important for shell scripting and will help you in more advanced scripting tasks. Keep practicing, and you'll be ready to manage real interstellar cargo inventories in no time!