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

1144 views bash

The bash script sends a curl The curl response example is


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

answered question

1 Answer


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?


Please login first before posting an answer.