Q:

Retrieve data from several Raspberry Pi disk images

I have about 40 Raspberry Pi SD-Card backups, dating back several years, with different projects, some of which I barely remember. As they are clogging up my harddrive (400+ GB), I would like to reduce them to a minimum. 
The files were mostly created with Win32 Disk Imager, a few maybe with dd.
I would prefer no to write them back to SD card, boot them and check what is on them. 
My idea was to mount them in Ubuntu, and retrieve the most common files and directories. 
I am mostly interested in:

the home directory (/home/pi , /home/*)
including the bash history (~/.bash_history)

I wrote this untested workflow, but I am not experienced with fdisk, grep and bash variables:
#!/bin/bash
for filename in /RPi_images/*.img; do
    # creating a filedir for the backed up data
    mkdir /RPi_data/$filename

    # retrieving boot start off the second partition
    bootstrt = $(fdisk -l $filename 2>&1 | grep -o 'img2\s*[0-9]*' | awk '{print $2}')

    # multiplying boot start with sector size
    # assuming every image has sectors of 512 bytes
    offst = $bootstrt * 512 

    # mount the partition
    sudo mount -v -o offset=$offst -t ext4 $filename ~/rpi_mnt

    # copy all files from home dir to back up folder 
    cp -a ~/rpi_mnt/home/. /RPi_data/$filename/home
done

Output of fdisk:
Disk /RPi_images/150101_project1.img: 7.4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xbbda3dc5

Device                                                   Boot Start      End  Sectors  Size Id Type
/RPi_images/150101_project1.img1       8192    93236    85045 41.5M  c W95 FAT32 (LBA)
/RPi_images/150101_project1.img2      94208 15523839 15429632  7.4G 83 Linux

How do I manage to get the variables $bootstrt $offstcorrect?
What else would you recommend an average pi user to back up?

A:

How do I manage to get the variables $bootstrt $offstcorrect?

You do not need them. You should losetup give a try. It is for beginners and will mount your images automagically. You do not have to fiddle with error prone offsets and it will simplify your script very much. For example I have used the Raspbian Buster Lite image:
pc ~$ sudo losetup --find --partscan --show 2019-09-26-raspbian-buster-lite.img
/dev/loop0

pc ~$ ls /dev/loop0*
/dev/loop0  /dev/loop0p1  /dev/loop0p2

pc ~$ sudo mkdir /mnt/p2
pc ~$ sudo mount /dev/loop0p2 /mnt/p2
pc ~$ sudo mount /dev/loop0p1 /mnt/p2/boot

You can mount how you like but I have mounted the partitions as they occur on the running system. If doing that you must have attention to the order of the mounts because the mountpoint for the boot partition (in this example) is only available after the first mount.
If you like you can attach another image:
pc ~$ sudo losetup --find --partscan --show another.img
/dev/loop1
pc ~$ ls /dev/loop1*
/dev/loop1  /dev/loop1p1  /dev/loop1p2

What else would you recommend an average pi user to back up?

I would suggest just to create a compressed archive. So you do not have to worry about to something forget. It will reduce the backup a lot because you only save the files and not the hole space of the image.
pc ~$ sudo tar -czf 2019-09-26-raspbian-buster-lite.tar.gz -V "Backup of Raspbian Buster Lite from mounted image" -C /mnt/p2 .   # dot as last character

Check with:
pc ~$ sudo tar -tvf 2019-09-26-raspbian-buster-lite.tar.gz

With unmount have attention to the reverse order:
pc ~$ sudo umount /mnt/p2/boot
pc ~$ sudo umount /mnt/p2

Don't forget to detach all images:
pc ~$ sudo losetup --detach-all

A:

How do I manage to get the variables $bootstrt $offstcorrect?

IMHO, Your initial approach is good.
I would just avoid using an hardcoded value for the sector size, just in case of ...
You maybe could use sfdisk instead of fdisk: it has been developped to ease scripting.
Oh, and:

To do arithmetic with bash, use the syntax offst=$((bootstrt*512)) (aka double-parenthesis)
You do not umount the filesystem at then end of your for loop... You'll probably encounter some problems ;-)
Instead of using the same mountpoint (~/rpi_mnt), which may cause problems if the previous run didn't umount correctly, i would instead use one temporary folder per iteration (mktemp -d ~/rpi_mountpoint.XXXX) and remove it at the end.

What else would you recommend an average pi user to back up?

If your project invovled GPIO and electronic stuff, i would backup /boot/config.txt too (for the dt-overlays stuff, etc...).
Maybe a backup of /etc/ may be a good idea too. 

