How’s The Weather I wonder how the weather is going to be like when I leave this
ID: 3870687 • Letter: H
Question
How’s The Weather
I wonder how the weather is going to be like when I leave this class or how the weather is like in New York or across the globe. Well let’s create a script for that. For this script we are going to create a menu that allows the user to select a predetermined location or opt to enter their own location. We are then going to use a CASE Statement to execute the user's choice. Use the following guidelines to write your script
Name The Script: my_weather
Echo Out The Following Menu To The User
Make A Selection To View The Forecast
1 ) Northridge, CA
2) New York, New York
3) Paris, France
4) View The Forecast For Another Location Using The Zip Code
Enter Your Selection [1-4]:
Create a CASE Statement that takes in the users selection as the main input. Depending on the user's selection, use the following to create the code blocks
User Selection
Code To Use
1
curl wttr.in/northridge_california
2
curl wttr.in/newyork
3
curl wttr.in/paris_france
4
Prompt User For Zip Code. Save To Variable Called “zip”
Then, use the following code to grab weather for zip
curl wttr.in/${zip}
Make a default block that alerts the user that they have made an invalid selection
Script is BASH
Make A Selection To View The Forecast
1 ) Northridge, CA
2) New York, New York
3) Paris, France
4) View The Forecast For Another Location Using The Zip Code
Enter Your Selection [1-4]:
Explanation / Answer
#!/bin/sh
echo "Make A Selection To View The Forecast"
echo "1 ) Northridge, CA"
echo "2) New York, New York"
echo "3) Paris, France"
echo "4) View The Forecast For Another Location Using The Zip Code"
read cinp
case $cinp in
"1")
curl wttr.in/northridge_california
break
;;
"2")
curl wttr.in/newyork
break
;;
"3")
curl wttr.in/paris_france
break
;;
"4")
echo "Enter the zip code"
read zip
curl wttr.in/$zip
break
;;
*)
echo "Sorry, Wrong input"
;;
esac
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.