0
0
Bash Scriptingscripting~30 mins

API interaction scripts in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
API Interaction Scripts
📖 Scenario: You work in a small company that needs to get weather information from an online service. You will write a simple Bash script to interact with a public weather API to get the current temperature for a city.
🎯 Goal: Build a Bash script that fetches weather data from an API and shows the temperature for a specific city.
📋 What You'll Learn
Create a variable with the city name
Create a variable with the API endpoint URL
Use curl to get the weather data
Extract the temperature value from the JSON response using jq
Print the temperature with a friendly message
💡 Why This Matters
🌍 Real World
Many jobs require fetching data from online services using scripts. This project shows how to automate getting live data like weather.
💼 Career
Scripting API calls is a common task for system administrators, developers, and data analysts to automate data retrieval and processing.
Progress0 / 4 steps
1
Set the city variable
Create a Bash variable called CITY and set it to the exact value London.
Bash Scripting
Need a hint?

Use the syntax VARIABLE_NAME="value" to create a variable in Bash.

2
Set the API URL variable
Create a Bash variable called API_URL and set it to the exact value https://api.open-meteo.com/v1/forecast?latitude=51.5074&longitude=-0.1278¤t_weather=true.
Bash Scripting
Need a hint?

Use double quotes to include the full URL string in the variable.

3
Fetch weather data and extract temperature
Use curl with the variable API_URL to get the weather data. Then use jq to extract the current temperature from the JSON path .current_weather.temperature. Save this temperature in a variable called TEMP.
Bash Scripting
Need a hint?

Use $(command) to capture command output into a variable.

Use curl -s to get data silently.

Use jq '.current_weather.temperature' to extract temperature.

4
Print the temperature with a message
Write a echo command to print: "The current temperature in London is X°C", where X is the value stored in the variable TEMP.
Bash Scripting
Need a hint?

Use echo and include the variable ${TEMP} inside the string.