sh Bash:goo.gl#使用Google URL Shortener服务(http://goo.gl)缩短网址。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Bash:goo.gl#使用Google URL Shortener服务(http://goo.gl)缩短网址。相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash
# Usage: goo.gl [URL]
#
# Shorten a URL using the Google URL Shortener service (http://goo.gl).
goo.gl() {
	[[ ! $1 ]] && { echo -e "Usage: goo.gl [URL]\n\nShorten a URL using the Google URL Shortener service (http://goo.gl)."; return; }
	curl -qsSL -m10 --connect-timeout 10 \
		'https://www.googleapis.com/urlshortener/v1/url' \
		-H 'Content-Type: application/json' \
		-d '{"longUrl":"'${1//\"/\\\"}'"}' |
		perl -ne 'if(m/^\s*"id":\s*"(.*)",?$/i) { print $1 }'
}

以上是关于sh Bash:goo.gl#使用Google URL Shortener服务(http://goo.gl)缩短网址。的主要内容,如果未能解决你的问题,请参考以下文章