shell http请求&处理返回值获取其中某个字段的值
并且第一个接口的返回值中部分参数得作为第二个接口的入参,所以做了如下shell验证
第一个接口返回的response body串:
{ "bizCode": "1", "bizDesc": "success", "item": [ { "age": "20", "name": "shaoshao" }, { "age": "21", "name": "shaoshaoqi" } ], "success": true }
处理shell:
#! /bin/bash #----------------------------- #auther__shaozhiqi #----------------------------- declare POST_URL=http://192.168.1.101:8040/user/all echo curl -i -X POST -H "'Content-type':'application/json'" '${POST_URL}' > temp.log cat temp.log >> info.log source temp.log > result biz_desc=$(cat result | sed 's/,/\n/g' | grep "bizDesc" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g'| sed 's/"//g') echo $biz_desc cat result >> info.log #接下来biz_desc的值就可以作为调用第二个接口的参数了 #这里只是验证,没有按照规范写
行结果: