# Get the top stories top_stories=$(curl -s 'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty') counter=1 # Convert the JSON array into a bash array InternalFieldSeparator IFS=',' read -ra story_ids <<< "$top_stories" # Loop through each story for story_id in "${story_ids[@]}"; do # Remove any non-digit characters from the story ID story_id=${story_id//[^0-9]/} # Get the story details story_json=$(curl -s "https://hacker-news.firebaseio.com/v0/item/$story_id.json?print=pretty") # Get the URL from the story details using grep url=$(echo "$story_json" | grep -oP '"url" : "\K[^"]+') # Check if the URL is not null or empty if [ -n "$url" ]; then # Call the URL using Lynx lynx -dump -accept_all_cookies -nolist -width 1000 -read_timeout=2 "$url" | head -n 500 >> "$counter.txt" let counter++ fi done