1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to simultaneously access two arrays indexes for a curl request in Bash for loop?

Discussão em 'StackOverflow' iniciado por fdantas, Dezembro 10, 2018.

  1. fdantas

    fdantas Administrator Moderador

    In Bash i am trying to query country currencies from http://free.currencyconverterapi.com/api/v5/convert?q=USD_GBP and update my OpenEdge API automatically without Hard coding the symbols. meaning I have to curl and save currency symbols from my API in an array and curl and save the values from the currency converter API. after that i want to run two for loops simultaneously or access the indexes of two arrays at the same time in order to run the API call that requires the

    url/rest/USD/12


    kind of input.

    In bash I am calling a curl that returns

    ZAR USD EUR BWP CHF GBP


    from my API in one line. Then i save that result in a variable called currency

    jsonEnd="_ZAR.val"
    symbolEnd="_ZAR"


    I then run

    values=()
    for j in ${currency[*]};
    do
    ${values[j]}=$(curl -X GET -H "Content-type: application/json" http://free.currencyconverterapi.com/api/v5/convert?q=${currency[j]}$symbolEnd&compact=y | jq '.${currency[j]}$jsonEnd')
    done


    To get the currency values into an array where '_ZAR.val' is a from a json result, tried to point at "val" with jq

    {
    "USD_ZAR": {
    "val": 14.23065
    } }


    at last i am trying to run a POST Curl which needs the relative currency symbol found above like USD with a value to update. in this form

    curl -X PUT -H "Content-Type: application/json" -H "Authorization: $context" http://192.168.xxx.xxx:8080/rest/exchangerates/USD/12


    i tried this

    for i in ${values[@]}
    do
    curl -X PUT -H "Content-Type: application/json" -H "Authorization: $context" http://192.168.xxx.xxx:8080/rest/exchangerates/${currency}/${values}
    done


    i can't get it right, the errors include

    curl: (6) Could not resolve host: USD_ZAR


    etc I am new to bash

    Continue reading...

Compartilhe esta Página