I have a bash shell script that performs a cURL command, and gets the raw output of an array inside the json array.
I can also successfully echo the number of elements in the array
Why can I not assign the amount of elements inside the array to a variable? it is always blank
output=$(curl --data '{"janus":"list_sessions","transaction":"123","admin_secret":"123"}' -H "Content-Type: application/json" http://127.0.0.1:7088/admin | jq --raw-output '.sessions')
echo $output
realoutput=$(output | jq '. | length')
echo $output | jq '. | length'
echo "OK|janusSessions=$realoutput"
The output of the following code is as follows:
[ 4218550436352653, 5053829616106050 ]
./list_janus_sessions.sh: 5: output: not found
2
OK|janusSessions=
What I have tried:
I have tried also:
output=$(curl --data '{"janus":"list_sessions","transaction":"123","admin_secret":"janusoverlord"}' -H "Content-Type: application/json" http://127.0.0.1:7088/admin | jq --raw-output '.sessions')
echo $output
realoutput=$output | jq '. | length'
echo $output | jq '. | length'
echo "OK|janusSessions=$realoutput"
Which produces:
[ 4218550436352653, 5053829616106050 ]
2
OK|janusSessions=
As you can see, the variable is always blank but here must be a simple way of doing this yet I cannot see it