Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 608

Shell script array element value not working in json post query

$
0
0

I have a some url array like below, Later I want to do some post method for each array element. somehow array element not working, but when I try direct url value its working.

# Print the uncommon URLsecho "Uncommon URLs:"printf "%s\n" "${uncommon_urls[@]}"IFS=$'\n' read -d '' -r -a array1 <<< "${uncommon_urls[@]}"getApp=$(curl -X GET -H "$headers" -H "Content-Type: application/json" "$uri")#echo $getAppfor url in "${array1[@]}"; do        echo $url        url=$(echo "$url" | rev | cut -c2- | rev)        echo $url        url=$(echo "$url" | tr -d '"')        echo $url       #getApp=$(echo "$getApp" | jq '.redirect_uris -= ["https://172.16.19.31:1111/login/callback"]')       getApp=$(echo "$getApp" | jq '.redirect_uris -= ["'$url'"]')       getAppnew=$(curl -X PUT -H "$headers" -H "Content-Type: application/json" -d "$getApp" "$uri")doneecho urslnewecho $getAppnew

output

Uncommon URLs:["https://172.xx.xx.31:3610/login/callback","https://172.xx.xx.31:3611/login/callback"]"https://172.xx.xx.31:3611/login/callback","https://172.xx.xx.31:3611/login/callback"https://172.xx.xx.31:3611/login/callback  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100  3411    0  1597  100  1814   2321   2636 --:--:-- --:--:-- --:--:--  4950"https://172.xx.xx.31:3612/login/callback","https://172.xx.xx.31:3612/login/callback"https://172.xx.xx.31:3612/login/callback  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100  3411    0  1597  100  1814   3013   3422 --:--:-- --:--:-- --:--:--  6423

Code which is working is below.If I put url value directly, its working

getApp=$(echo "$getApp" | jq '.redirect_uris -= ["https://172.xx.xx.31:1111/login/callback"]')

If I define manually like this all works fine

uncommon_urls=("https://172.16.19.31:12163/login/callback""https://172.16.19.31:20383/login/callback""https://172.16.19.31:31990/login/callback""https://172.16.19.31:21480/login/callback""https://172.16.19.31:2851/login/callback""https://172.16.19.31:8549/login/callback""https://172.16.19.31:11092/login/callback""https://172.16.19.31:11092/auth/login/callback""https://172.16.19.31:3355/auth/login/callback""https://172.16.19.31:10602/auth/login/callback")

Viewing all articles
Browse latest Browse all 608

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>