1. 程式人生 > 其它 >linux curl & jq命令

linux curl & jq命令

curl

-x IP address 使用代理

-X GET get請求

-X POST post請求

-d 'xxx'post請求傳參

-o file name 儲存相應內容到檔案

-v 顯示通訊整個過程

-s 不輸出錯誤和進度資訊

 

jq

json提取處理器

練習:

manshuo@Dashuo:~/temp$ echo '{"a":10,"b":20}'
{"a":10,"b":20}
manshuo@Dashuo:~/temp$ echo '{"a":10,"b":20}'|jq .
{
  "a": 10,
  "b": 20
}
manshuo@Dashuo:~/temp$ echo '{"a":10,"b":20}'|jq '.[]'
10
20

manshuo@Dashuo:~/temp$ echo '[{"a":10,"b":20},{"c":30},{"d":333}]'|jq '.[]'
{
  "a": 10,
  "b": 20
}
{
  "c": 30
}
{
  "d": 333
}
manshuo@Dashuo:~/temp$ echo '[{"a":10,"b":20},{"c":30},{"d":333}]'|jq '.[1]'
{
  "c": 30
}
manshuo@Dashuo:~/temp$ echo '[{"a":10,"b":20},{"c":30},{"d":333}]'|jq '.[1,1]'
{
  "c": 30
}
{
  "c": 30
}
manshuo@Dashuo:~/temp$ echo '[{"a":10,"b":20},{"c":30},{"d":333}]'|jq '.[0,1]'
{
  "a": 10,
  "b": 20
}
{
  "c": 30
}


manshuo@Dashuo:~/temp$ echo '{"a":10,"b":20}'|jq '.[]'
10
20

manshuo@Dashuo:~/temp$ echo '{"a":10,"b":20}'|jq '[.a,.b]'
[
  10,
  20
]


manshuo@Dashuo:~/temp$ echo '{"a":10,"b":20}'|jq '{"f":.a,"f2":.b}'
{
  "f": 10,
  "f2": 20
}