For the evaluation to proceed with the declare
command, you must pass a string with the whole content embraced by parentheses, which is the proper syntax for array declaration in bash (declare -a VAR=([key]=val ...)
). For example, your command should be:
$ DISK=sda
$ declare -a PARTS='('$(awk -v disk=$DISK \
'$4 ~ disk {printf "[" $2 "]=\"" $3 "\" "}' /proc/partitions)')'
You may as well check out what the proper syntax is by simply dumping the array. This is the result after running the awk
command in my machine:
$ declare -p PARTS
declare -a PARTS='([0]="488386584" [1]="25165824" [2]="16777216" \
[3]="8388608" [4]="438053895")'