开发者

pbcopy Specific Part of Shell Script

开发者 https://www.devze.com 2023-04-01 13:08 出处:网络
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 \\

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

精彩评论

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