$ get_sun.sh

#!/bin/sh

JSON=$( curl -s ifconfig.co/json )

LAT=$( echo "$JSON" | jq .latitude )

LON=$( echo "$JSON" | jq .longitude )

TZ_OFFSET=$( date +%z | cut -c1,2,3 | tr -d '+' | sed 's/^0*//' )

hdate -s -l "$LAT" -L "$LON" --timezone "$TZ_OFFSET" | grep -iE 'SUNRISE|SUNSET'

# can you make it shorter?

Reply to this note

Please Login to reply.

Discussion

echo "SUNRISE: $(hdate -s -l $(curl -s ifconfig.co/json | jq -r '.latitude') -L $(curl -s ifconfig.co/json | jq -r '.longitude') --timezone $(date +%z | cut -c1-3 | tr -d '+') | grep -i 'SUNRISE')"

echo "SUNSET: $(hdate -s -l $(curl -s ifconfig.co/json | jq -r '.latitude') -L $(curl -s ifconfig.co/json | jq -r '.longitude') --timezone $(date +%z | cut -c1-3 | tr -d '+') | grep -i 'SUNSET')"