Last active
June 26, 2022 18:39
-
-
Save yoplait/becbefa04958e2e1dd1ac919b6c53733 to your computer and use it in GitHub Desktop.
Exercise 2: Find all ships that have a hyperdrive rating >= 1.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
########################################################################################## | |
# Exercise 2: Find all ships that have a hyperdrive rating >= 1.0 | |
clear | |
URL='https://swapi.dev/api' | |
PAGE=1 | |
echo "" | |
echo "Exercise 2: Find all ships that have a hyperdrive rating >= 1.0" | |
echo "" | |
while true | |
do | |
response=$( curl -sL -H 'Accept: application/json' ${URL}/starships?page=${PAGE} ) | |
if [[ ${response} =~ .*detail.*Not.* ]]; then | |
break | |
fi | |
echo $response | jq '.results[] | select(.hyperdrive_rating>="1.0").name' | |
PAGE=$((PAGE + 1)) | |
done | |
echo "" | |
echo "API Pages:" $((PAGE - 1)) | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment