我发现sed 响应 (curl) 的值现在我需要一些帮助来获取我在文件中打印的值并在同一 .sh 脚本中的另一个子字符串中使用它
这是服务器的响应:
{"status":{"code":"STATUS_OK","message":"ServiceUUID sent successfully via..."},"body":{"data":{"userApps":{},"username":"HereTheUsername","fullName":"NameOfTheAccountPossessor","lang":"sq","blocked":false,"lastLogin":"2016-10-10T17:19:22","passwordResetUuid":"6147dc32-b72e-450a-8084-2fdb5319a931","userAccessLevel":5,"countDownSeconds":0,"serviceUuid":"7260276c-5c3f-41d3-9329-3603acecb7e5","userAttributes":{},"labelMap":{},"id":"APPUSER00000012","someLabel":"NameOfTheOrganisation"}}}
所以我找到了值“serviceUuid”:
fuid=$(echo "$uuid" | sed -nE 's/.*"serviceUuid":"(.*)","user.*/\1/p' >> final.txt)
现在我想获取这个值(在文件 Final.txt 中)并将其粘贴到名为 aass.sh 的脚本的同一文件中的该字符串上:
login=$(curl -X POST -H "ACCEPT-LANGUAGE:en" -H "Content-Type: application/json;charset=utf-8" -H "Accept-Encoding:gzip" -H "Accept: application/json" -d {"serviceUuid":"**HERE**"} UrlOfTheSite)
我该怎么办?
答案1
假设仅最近的 uuid 存储在 Final.txt 中,这应该可以做到...
service_uuid=$(cat final.txt)
login=$(curl -X POST -H "ACCEPT-LANGUAGE:en" -H "Content-Type: application/json;charset=utf-8" -H "Accept-Encoding:gzip" -H "Accept: application/json" -d {"serviceUuid":"${service_uuid}"} UrlOfTheSite)
如果没有看到整个脚本,就很难准确地知道 Final.txt 中的内容,但请记住,您使用的是追加重定向 (>>),而不是覆盖 (>),因此该文件可能会保留运行列表全部uuid 是脚本接收到的。