How do I get the UUID of a partition and define a Bash variable as being equal to it?

Note that's the UUID of the filesystem (or other structured data with a UUID the udev scripts know about) on the partition, not the UUID of the partition itself (not all partitioning schemes give UUIDs to partition anyway). See also Difference between UUID from blkid and mdadm?.

A few options on Linux-based systems to get the FS UUID:

fs_uuid=$(blkid -o value -s UUID /dev/sdb1)
fs_uuid=$(lsblk -no UUID /dev/sdb1)
fs_uuid=$(udevadm info -n sdb1 -q property | sed -n 's/^ID_FS_UUID=//p')
fs_uuid=$(find /dev/disk/by-uuid -lname '*/sdb1' -printf %f)

The first one may require superuser privileges or at least the right to read the device.

If the filesystem is mounted, you can also use:

fs_uuid=$(findmnt -fn -o UUID /dev/sdb1)

You can do it in this way

PART_ID=$(blkid -o value -s UUID /dev/sdb1)