I am having unexpected results in expanding an array. I am hoping someone can shed some light on why I am seeing what I am seeing. I am trying to populate an array using fdisk -l to fill it and only getting a single element. The code:
#!/bin/bash
declare -a PARTITIONS=();
PARTITIONS=$(fdisk -l ubuntu-minimal-16.04-desktop-armhf-raspberry-pi-2.img | grep -i ubuntu-minimal-16.04-desktop-armhf-raspberry-pi-2.img | sed '/Disk/d' | cut -d " " -f1)
echo "PARTITIONS[@]:${PARTITIONS[@]}"
echo "ELEMENT 0: ${PARTITIONS[0]}"
echo "ELEMENT 1: ${PARTITIONS[1]}"
Output:
PARTITIONS[@]:ubuntu-minimal-16.04-desktop-armhf-raspberry-pi-2.img1 ubuntu-minimal-16.04-desktop-armhf-raspberry-pi-2.img2
ELEMENT 0: ubuntu-minimal-16.04-desktop-armhf-raspberry-pi-2.img1 ubuntu-minimal-16.04-desktop-armhf-raspberry-pi-2.img2
ELEMENT 1:
There is no element 1. What am I doing wrong?
ubuntu-minimal-16.04-desktop-armhf-raspberry-pi-2.img2, you may notice that it is part of element 0.