How to extract values from a command with multi-line output?
Bo Berglund
bo.berglund at gmail.com
Mon Apr 4 23:11:07 UTC 2022
On Mon, 04 Apr 2022 23:02:37 +0200, Bo Berglund <bo.berglund at gmail.com> wrote:
>So the lines clearly do not get split into a 2-element array, instead line 2 is
>lost in the array.
>
>What am I doing wrong here?
So I realized that I do not have to mess with 2-dim array.
I just call fdisk twice and grab different 1-line output:
# Inspect the image file:
# First the boot partition:
CMD="fdisk -lu $IMGFILE | tail -n 2 | head -n 1"
DSKDATA=$(eval "$CMD")
IFS=' '
read -ra data_array <<< "$DSKDATA"
BOOTSTRT="${data_array[1]}"
BOOTSIZE="${data_array[3]}"
# Next the root partition:
CMD="fdisk -lu $IMGFILE | tail -n 1"
DSKDATA=$(eval "$CMD")
read -ra data_array2 <<< "$DSKDATA"
ROOTSTRT="${data_array2[1]}"
#Now mount the image files
eval "sudo mount -t ext4 -o loop,offset=$((${ROOTSTRT}*512)) $IMGFILE $MNTDIR"
eval "sudo mount -t vfat -o
loop,offset=$((${BOOTSTRT}*512)),sizelimit=$((${BOOTSIZE}*512)) $IMGFILE
${MNTDIR}/boot"
This works fine...
Sorry for the noise.
--
Bo Berglund
Developer in Sweden
More information about the ubuntu-users
mailing list