How do I get a string from a curl response for a variable in bash?

1144 views bash
6

The bash script sends a curl The curl response example is

    {"code":"2aaea70fdccd7ad11e4ee8e82ec26162","nonce":1541355854942}

I need to get the random code "2aaea70fdccd7ad11e4ee8e82ec26162" (without quotes) and use it in the bash script.

answered question

1 Answer

0

Use jq to extract the value from the JSON, and command substitution to capture the output of the command:

code=$(curl ... | jq -r '.code')

posted this

Have an answer?

JD

Please login first before posting an answer.