On 3/30/21 10:54 AM, Chet Ramey wrote: > On 3/29/21 6:40 PM, Eric Cook wrote:
>> Its just when populating that array dynamically with another array >> if that second array didn't contain `v1' hypothetically, the array gets >> shifted to > > OK, how would you do that? What construct would you use in this scenario? > Sample input: $ exiftool -j *.flac | jq -r '.[]| {Artist, Track, Genre, Title}|to_entries[]| .key + "|" + .value' Artist|AK420 Track| Genre|lofi Title|A2 - Northern Lights -- typeset -A tags=(); set -- while IFS='|' read -ra ary; do set -- "$@" "${ary[@]}" done < <( exiftool -j *.flac | jq -r '.[]| {Artist, Track, Genre, Title}|to_entries[]| .key + "|" + .value' ) eval 'tags=('"${*@Q}"\) typeset -p tags declare -A tags=([lofi]="Title" [Track]="Genre" [Artist]="AK420" ["A2 - Northern Lights"]="" ) >> a=( [k1]=k2 [v2]=k3 [v3]= ) >> which i would imagine to be unexpected for the author of the code and would >> rather >> it error out instead of chugging along. > > Wouldn't this be a programming error? If this were a concern, since any > array can have elements with empty values, I would recommend a different > strategy to copy it. > Yeah, it is a programming error that could've used better validation. I just find it weird that the assumption of an assignment with an odd number of elements with this new syntax is that the odd number element is always a key missing a value that is filled in. when any of the keys or values could've been missing during the assignment.