My goal is to create a list of partitions for each block device listed in /sys/block
;
#!/bin/bash
block_devices_list=($(ls /sys/block))
partition_list=($(cat /proc/partitions | awk '{print $4}'))
unset partition_list[0]
for block_device in ${block_devices_list[@]}; do
for partition in ${partition_list[@]}; do
partitions+=($(echo $partition | grep $block_device))
done
# Right here?
unset partitions
done
Every time the outside 'for loop' completes it's cycle it ends up with an array of partitions for a particular block device. At that point I would like to transfer that data to a separate array, dynamically named after the device it belongs to (like 'partitions_sda' for example).
I have read a few questions/answers about 'dynamic' variable names, 'associative' arrays and whatnot but don't seem to be able to figure this out. Any help much appreciated.