-2

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"

oguz ismail
  • 1
  • 16
  • 47
  • 69
anuruddhas
  • 55
  • 5

1 Answers1

1

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.

ikegami
  • 367,544
  • 15
  • 269
  • 518
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123