Finding the Pirate's Treasure

ShellShellBeginner
Practice Now

Introduction

Captain Blackbeard has hidden his treasure on a remote island and left behind a series of clues encoded as shell variables and arithmetic operations. In this challenge, you will complete a partially written shell script to decode these clues and locate the treasure.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL shell(("Shell")) -.-> shell/VariableHandlingGroup(["Variable Handling"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) shell(("Shell")) -.-> shell/AdvancedScriptingConceptsGroup(["Advanced Scripting Concepts"]) shell/VariableHandlingGroup -.-> shell/variables_decl("Variable Declaration") shell/VariableHandlingGroup -.-> shell/variables_usage("Variable Usage") linux/BasicFileOperationsGroup -.-> linux/chmod("Permission Modifying") shell/AdvancedScriptingConceptsGroup -.-> shell/arith_ops("Arithmetic Operations") shell/AdvancedScriptingConceptsGroup -.-> shell/arith_expansion("Arithmetic Expansion") subgraph Lab Skills shell/variables_decl -.-> lab-388807{{"Finding the Pirate's Treasure"}} shell/variables_usage -.-> lab-388807{{"Finding the Pirate's Treasure"}} linux/chmod -.-> lab-388807{{"Finding the Pirate's Treasure"}} shell/arith_ops -.-> lab-388807{{"Finding the Pirate's Treasure"}} shell/arith_expansion -.-> lab-388807{{"Finding the Pirate's Treasure"}} end

Decoding the Treasure Map

The treasure map has been encoded into a shell script that needs to be completed. The script uses basic arithmetic operations to convert the initial coordinates into the final location. Your task is to fill in the missing values and calculations to reveal where the treasure is buried.

Tasks

Complete the treasure_map.sh script in the /home/labex/project directory by:

  • Assigning the correct initial values to the LATITUDE and LONGITUDE variables.
  • Implementing arithmetic operations to calculate PACES_NORTH and PACES_EAST.

Requirements

  1. The shell script treasure_map.sh is located in /home/labex/project with the following code structure:
#!/bin/bash

## Assign the correct values to these variables
LATITUDE=
LONGITUDE=

## Calculate the paces using arithmetic operations
PACES_NORTH=
PACES_EAST=

## Don't modify the line below
echo "The treasure is buried $PACES_NORTH paces north and $PACES_EAST paces east from the old oak tree."
  1. Use these values and calculations:

    • Set LATITUDE to 15.
    • Set LONGITUDE to 25.
    • Calculate PACES_NORTH as latitude multiplied by 2.
    • Calculate PACES_EAST as longitude divided by 5.
  2. The script will output the treasure location in this format:

The treasure is buried X paces north and Y paces east from the old oak tree.

Where X and Y are the calculated values.

Example Output

The treasure is buried 30 paces north and 5 paces east from the old oak tree.

Hints

  • Make sure the script is executable by using chmod +x.
โœจ Check Solution and Practice

Summary

In this challenge, you have learned the fundamentals of shell scripting:

  • Assigning values to variables.
  • Performing arithmetic operations in shell scripts.
  • Executing scripts and formatting output.

These skills are foundational for more complex shell scripting tasks.