开发者

pbcopy Specific Part of Shell Script

I am using the goo.gl URL shortener to shorten URL's with a curl command. The command is below:

curl https://www.googleapis.com/urlshortener/v1/url \
  -H 'Content-Type: application/json' \
  -d '开发者_运维问答{"longUrl": "http://www.google.com/"}'

This returns the response is below:

{
 "kind": "urlshortener#url",
 "id": "http://goo.gl/fbsS",
 "longUrl": "http://www.google.com/"
}

Is there a way to use pbcopy to only copy the shortened URL? (http://goo.gl/fbsS)

I am new to posting on StackOverflow, and would appreciate any responses I can get.


Try this:

$ curl ... | grep '"id":' | cut -d\" -f 4 | pbcopy
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜