Weather Advisory System

ShellShellBeginner
Practice Now

Introduction

Imagine you're developing a simple weather advisory system for a local meteorology office. Your task is to complete a shell script that provides weather advice based on temperature input. This challenge will test your understanding of shell scripting if statements and basic user input handling.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicSystemCommandsGroup(["Basic System Commands"]) shell(("Shell")) -.-> shell/VariableHandlingGroup(["Variable Handling"]) shell(("Shell")) -.-> shell/ControlFlowGroup(["Control Flow"]) shell(("Shell")) -.-> shell/AdvancedScriptingConceptsGroup(["Advanced Scripting Concepts"]) linux/BasicSystemCommandsGroup -.-> linux/echo("Text Display") shell/VariableHandlingGroup -.-> shell/variables_usage("Variable Usage") shell/ControlFlowGroup -.-> shell/if_else("If-Else Statements") shell/ControlFlowGroup -.-> shell/cond_expr("Conditional Expressions") shell/AdvancedScriptingConceptsGroup -.-> shell/arith_expansion("Arithmetic Expansion") subgraph Lab Skills linux/echo -.-> lab-388885{{"Weather Advisory System"}} shell/variables_usage -.-> lab-388885{{"Weather Advisory System"}} shell/if_else -.-> lab-388885{{"Weather Advisory System"}} shell/cond_expr -.-> lab-388885{{"Weather Advisory System"}} shell/arith_expansion -.-> lab-388885{{"Weather Advisory System"}} end

Complete the Weather Advisory Script

Tasks

  1. Navigate to the ~/project directory where you'll find a partially completed script named weather_advisor.sh.
  2. Open the weather_advisor.sh file and complete the if statements to provide weather advice based on the temperature input.

Requirements

  • The script weather_advisor.sh is already created in the ~/project directory with a basic structure.
  • The script already includes the shebang and user input prompt.
  • Your task is to complete the if statements to provide the following advice:
    • If the temperature is below 0°C: "It's freezing! Wear a heavy coat and gloves."
    • If the temperature is between 0°C and 10°C (inclusive): "It's cold. A warm jacket is recommended."
    • If the temperature is between 11°C and 20°C (inclusive): "It's cool. A light jacket should suffice."
    • If the temperature is above 20°C: "It's warm. Enjoy the pleasant weather!"
  • Use echo to display the advice to the user.

Example

Here's an example of how the completed script should work:

$ ./weather_advisor.sh
Enter the current temperature in Celsius: 15
It's cool. A light jacket should suffice.

$ ./weather_advisor.sh
Enter the current temperature in Celsius: -2
It's freezing! Wear a heavy coat and gloves.

$ ./weather_advisor.sh
Enter the current temperature in Celsius: 25
It's warm. Enjoy the pleasant weather!

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

✨ Check Solution and Practice

Summary

In this challenge, you completed a simple weather advisory system using shell scripting. You practiced using if statements to make decisions based on user input and provided appropriate output using echo. This exercise reinforced your understanding of conditional logic in shell scripts and demonstrated a practical application of these concepts in a real-world scenario.