When I do this:
arr=($(echo '{"crew":[{"name":"kirk"},{"name":"bones"},{"name":"mr spock"}]}' | jq -r '.crew[].name | @sh'))
I get:
echo "${arr[2]}"
mr
echo "${arr[3]}"
spock
However when I do this:
arr=("kirk" "bones" "mr spock")
I get this:
echo "${arr[2]}"
mr spock
Why, in the first example, is bash ignoring the quotes that each jq value is wrapped in when it creates the array?
When I do this:
arr=($(echo '{"crew":[{"name":"kirk"},{"name":"bones"},{"name":"mr spock"}]}' | jq -r '.crew[].name | @sh'))
I get:
echo "${arr[2]}"
mr
echo "${arr[3]}"
spock
However when I do this:
arr=("kirk" "bones" "mr spock")
I get this:
echo "${arr[2]}"
mr spock
Why, in the first example, is bash ignoring the quotes that each jq value is wrapped in when it creates the array?
When I do this:
arr=($(echo '{"crew":[{"name":"kirk"},{"name":"bones"},{"name":"mr spock"}]}' | jq -r '.crew[].name | @sh'))
I get:
echo "${arr[2]}"
mr
echo "${arr[3]}"
spock
However when I do this:
arr=("kirk" "bones" "mr spock")
I get this:
echo "${arr[2]}"
mr spock
Why, in the first example, is bash ignoring the quotes that each jq value is wrapped in when it creates the array?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.