Identify a partition from script

Solution 1:

Here's a demonstration script which uses stat to print the device identifier of the running script. The device identifier can then be used to get the partition name with a utility such as diskutil.

#! /bin/bash
#
#  whscript: Print the Device Identifier
#            of the running script
#

#  This will return the name of the script

echo "$0"

#  Use stat to produce the Device Identifier

stat -f '%Sd' -- "$0"

#  Have diskutil print information
#  about the Device Identifier. Parse as
#  needed

diskutil info "$(stat -f '%Sd' -- "$0")"