From bc07222cd026967cb4678d54a1d36261dfd3b014 Mon Sep 17 00:00:00 2001 From: Alex Epstein Date: Thu, 9 Nov 2017 08:58:30 -0500 Subject: [PATCH] Implemented the shorten URL --- short/short | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/short/short b/short/short index 5574dbf..b2bd4b6 100755 --- a/short/short +++ b/short/short @@ -146,9 +146,10 @@ fi shortenURL() { -response=$(curl -A curl -s -i -H "Content-Type: application/json" -X POST -d "{\"url\": \"$1\"}" http://ki.tc/ || exit 1) -returnedURL=$(echo $response | head -n 5 | tail -n 1 | grep -Eo "/[a-Z 0-9]*" | tail -n 1 2> /dev/null) -returnedURL="http://ki.tc"$returnedURL +newURL=$(echo $1 | grep -Eo "^[h]ttp[s]?://") +if [[ $newURL == "" ]]; then newURL="http://"$1; fi +response=$(curl -A curl -s -i -H "Content-Type: application/json" -X POST -d "{\"url\": \"$newURL\"}" http://ki.tc/ || exit 1) +returnedURL=$(echo $response | grep -Eo "http://ki.tc/[0-9a-zA-Z]*" | tail -n 1) } printResults() @@ -165,7 +166,7 @@ printShortenedResults() { cat <