summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-02-17 23:59:44 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-02-17 23:59:44 +0100
commit07118cc322d1effbc5ff63dbc1a38708797a084f (patch)
tree56731b97bca96f907c305cea5bc587cb90dd1034
parent837d9bc7ddc0ef4dd92c33b14527f190c2dd9925 (diff)
downloadISS_Above-07118cc322d1effbc5ff63dbc1a38708797a084f.tar.gz
Make shellcheck happy
-rwxr-xr-xiss_above.sh22
1 files changed, 16 insertions, 6 deletions
diff --git a/iss_above.sh b/iss_above.sh
index 1866c14..ac6560b 100755
--- a/iss_above.sh
+++ b/iss_above.sh
@@ -4,13 +4,19 @@ set -eu
API_URL='http://api.open-notify.org/iss-now.json'
GEOIP_URL="https://ipapi.co/json"
+if [ "$#" -gt 0 ] ; then
+ OUTPUT="$1"
+else
+ OUTPUT=""
+fi
+
API_data=$(curl -s "$API_URL")
-latitude="$(echo $API_data|jq -r '. | .iss_position.latitude')"
-longitude="$(echo $API_data|jq -r '. | .iss_position.longitude')"
+latitude="$(echo "$API_data"|jq -r '. | .iss_position.latitude')"
+longitude="$(echo "$API_data"|jq -r '. | .iss_position.longitude')"
my_location=$(curl -s "$GEOIP_URL")
-my_lat=$(echo $my_location | jq -r '. | .latitude')
-my_long=$(echo $my_location | jq -r '. | .longitude')
+my_lat=$(echo "$my_location" | jq -r '. | .latitude')
+my_long=$(echo "$my_location" | jq -r '. | .longitude')
# my_lat="50.0769160"
# my_long="14.4740344"
@@ -89,5 +95,9 @@ EOF
}
# distance lat1 lon1 lat2 lon2 → metres (rounded to millimetres), error < ¼%
-dist="$(distance $latitude $longitude $my_lat $my_long)"
-printf "%'d km\n" $(( "${dist%.*}" / 1000 ))
+dist="$(distance "$latitude" "$longitude" "$my_lat" "$my_long")"
+if [ -n "$OUTPUT" ] ; then
+ printf "%'d km\n" $(( "${dist%.*}" / 1000 )) >"$OUTPUT"
+else
+ printf "%'d km\n" $(( "${dist%.*}" / 1000 ))
+fi