The following is actually buggy:
# BAD: Output line of * is replaced with list of local files; can't deal with whitespace arr=( $( curl -k "$url" | jq -r '.[].item2' ) )
If you have bash 4.4 or newer, a best-of-all-worlds option is available:
# BEST: Supports bash 4.4+, with failure detection and newlines in data { readarray -t -d '' arr && wait "$!"; } < <( set -o pipefail curl --fail -k "$url" | jq -j '.[].item2 | (., "\u0000")' )
...whereas with bash 4.0, you can have terseness at the cost of failure detection and literal newline support:
# OK (with bash 4.0), but can't detect failure and doesn't support values with newlines readarray -t arr < <(curl -k "$url" | jq -r '.[].item2' )
...or bash 3.x compatibility and failure detection, but without newline support:
# OK: Supports bash 3.x; no support for newlines in values, but can detect failures IFS=$'\n' read -r -d '' -a arr < <( set -o pipefail curl --fail -k "$url" | jq -r '.[].item2' && printf '\0' )
...or bash 3.x compatibility and newline support, but without failure detection:
# OK: Supports bash 3.x and supports newlines in values; does not detect failures arr=( ) while IFS= read -r -d '' item; do arr+=( "$item" ) done < <(curl --fail -k "$url" | jq -j '.[] | (.item2, "\u0000")')