Linux Tips and Tricks

Linux Tips and Tricks

Shorten long urls using curl command – shell script

September21

tinyurl is providing a api call to shorten the long url. So, we can make a api call using the curl command and get the short url from the long url.

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
 
#  This script is used to shorten the long url
#  Author  : Kamaraj Subramanian
#  Website : www.thelinuxtips.com
 
echo -n "Enter the Long URL : "
read url
 
short_url=$(curl -s http://tinyurl.com/api-create.php?url=${url})
 
echo "Short URL is : ${short_url}"

Output

1
2
3
4
5
6
7
8
9
10
11
$ ./shorten.sh
Enter the Long URL : http://www.google.com/finance?cid=694653
Short URL is : http://tinyurl.com/lhu73
 
$ ./shorten.sh
Enter the Long URL : https://sites.google.com/site/gdevelopercodelabs/app-engine/python-codelab
Short URL is : http://tinyurl.com/2vb7e2e
 
$ ./shorten.sh
Enter the Long URL : http://www.flickr.com/services/apps/tags/Linux
Short URL is : http://tinyurl.com/9za9z32
posted under Uncategorized

Email will not be published

Website example

Your Comment:


Recent Comments

    Categories