get field from json and assign to variable in bash script? -


i have json store in jsonfile

{   "key1": "aaaa bbbbb",   "key2": "cccc ddddd" } 

i have code in mycode.sh:

#!/bin/bash value=($(jq -r '.key1' jsonfile)) echo "$value" 

after run ./mycode.sh result aaaa if run jq -r '.key1' jsonfile result aaaa bbbbb

could me?

with line of code

value=($(jq -r '.key1' jsonfile)) 

you assigning both values array. note outer parantheses () around command. can access values individually or echo content of entire array.

$ echo "${value[@]}" aaaa bbbb  $ echo "${value[0]}" aaaa  $ echo "${value[1]}" bbbb 

since echoed $value without specifying value want first value of array.


Comments

Popular posts from this blog

rest - Spring boot: Request method 'PUT' not supported -

php - Magento - Deleted Base url key -

symfony - imagine_filter() not generating the correct url in LiipImagineBundle -