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
- Open the existing shell script named
cargo_manifest.shin the/home/labex/projectdirectory. - Complete the script by filling in the missing parts to create and display the ship's cargo inventory.
- Run the script with different arguments to display each cargo bay's inventory.
Requirements
- The script
cargo_manifest.shis already created in the/home/labex/projectdirectory with a code framework. - Complete the script by:
- Creating three arrays named
forward_bay,midship_bay, andaft_bay. - Each array should contain exactly 3 items (strings) representing cargo items.
- Use the
$1variable to check which cargo bay inventory to display. - Display the inventory of the requested cargo bay using
echostatements.
- Creating three arrays named
- The script should accept one argument: either "forward", "midship", or "aft".
- If no argument is provided, the script should display: "Please specify a cargo bay: forward, midship, or aft"
- 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.
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!



