Skip to content

Instantly share code, notes, and snippets.

@theirix
Created March 1, 2012 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theirix/1953269 to your computer and use it in GitHub Desktop.
Save theirix/1953269 to your computer and use it in GitHub Desktop.
Detect disk volume label
#!/bin/sh
VOL=$1
if [ -z "$VOL" ] ; then
echo Usage: $0 vol
exit 1
fi
LABEL=""
command -v e2label > /dev/null && [ -z "$LABEL" ] && LABEL=`e2label $VOL 2>/dev/null`
command -v dosfslabel > /dev/null && [ -z "$LABEL" ] && LABEL=`dosfslabel $VOL 2>/dev/null`
command -v ntfslabel > /dev/null && [ -z "$LABEL" ] && LABEL=`ntfslabel -f $VOL 2>/dev/null`
command -v volname > /dev/null && [ -z "$LABEL" ] && LABEL=`volname $VOL 2>/dev/null`
command -v jfs_tune > /dev/null && [ -z "$LABEL" ] && LABEL=`jfs_tune -l $VOL 2>/dev/null`
command -v reiserfstune > /dev/null && [ -z "$LABEL" ] && LABEL=`reiserfstune -l $VOL 2>/dev/null`
command -v xfs_admin > /dev/null && [ -z "$LABEL" ] && LABEL=`xfs_admin -l $VOL 2>/dev/null`
echo $LABEL
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment