Issue
Below jq query output comes correctly.
ROUTE_ID= jq -r '.[][]? | select(.pattern? == "*test.com/testcards/email/*").id' route.json
route.json file contains a json output.
But echo "this is route $ROUTE_ID" or echo "this is route $ROUTE_ID does not return value for $ROUTE_ID"
Solution
What you are currently doing is setting the environment variable ROUTE_ID to nothing for the execution of jq, eg:
MY_ENV=abc command
Will set the environment variable "MY_ENV" to "abc" for the execution of command.
What you want to do is store the output of your command a variable, for this you'll need to use command substitutions:
my_var=$(command)
In your case:
route_id=$(jq -r '.[][]? | select(.pattern? == "test.com/testcards/email/").id' route.json)
Nitpicking; use lowercase variable names when possible, as UPPER_CASE are "reserved" for exported environment variables.
Answered By - Andreas Louv Answer Checked By - Katrina (WPSolving Volunteer)