#!/bin/bash # Given social media links on stdin or as args, this extracts the link in the profile description, if any. function verbose_echo { if [[ "${verbose}" ]] then echo "$@" fi } function fetch { verbose_echo "Fetching $1" >&2 curl -sL --max-time 10 -A 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0' "$1" } function fetch_n_extract { url="$1" if [[ "${url}" == *'facebook.com/'* ]] then page="$(fetch "${url}")" if grep -qF '"tab_home"' <<<"${page}" then # Publicly accessible profile grep -Po '"website_url":"\K[^"]+' <<<"${page}" | sed 's,\\/,/,g' | awk '!seen[$0]++' elif grep -qF 'id="pagelet_loggedout_sign_up"' <<< "${page}" then # Profile overview only grep -Po '