diff --git a/linkloc b/linkloc index fa2796c..b3c6b93 100644 --- a/linkloc +++ b/linkloc @@ -1,16 +1,11 @@ #!/bin/bash -if [ -z $1 ]; then echo "linkInvalid"; exit 1; fi; -URL="${1}" +if [ -z "${1}" ]; then echo "linkInvalid"; exit 1; fi; -HEADS=$(curl -L --head --silent -A "getloc" "$URL"); -STATUS=$(echo "$HEADS" | head -1); -LOCATION=$(echo "$HEADS" | grep -ie '^location' | grep -e 'http../' \ -| tail -1 | cut -d'?' -f1 | cut -d' ' -f2 | sed 's@^.*reddit.com@https://old.reddit.com@' \ +LOCATION=$(\ + curl -L --head --silent -A "getloc" "${1}" | grep -ie '^location' \ + | grep -e 'http../' | tail -1 | cut -d'?' -f1 | cut -d' ' -f2 \ + | sed 's@^.*reddit.com@https://old.reddit.com@' \ ) - -if [ -z "$LOCATION" ]; then -echo "$URL"; exit 2; -fi -echo "$LOCATION" \ No newline at end of file +if [ -z "$LOCATION" ]; then echo "${1}"; else echo "$LOCATION"; fi \ No newline at end of file