Skip to content

Instantly share code, notes, and snippets.

@m-tmatma
Last active July 8, 2022 02:11
Show Gist options
  • Save m-tmatma/0924b52df64906dd80e142cfbd886d17 to your computer and use it in GitHub Desktop.
Save m-tmatma/0924b52df64906dd80e142cfbd886d17 to your computer and use it in GitHub Desktop.
#!/bin/sh
PRECHECK=$(ls /dev/disk/by-id/* | grep usb | wc -l)
if [ $PRECHECK -eq 0 ]; then
echo No USB block devices are connected.
exit 1
fi
NUMUSBDEVICES=$(ls /dev/disk/by-id/usb* -1 | xargs readlink -f | grep -E '[a-z]+$' | wc -l)
if [ $NUMUSBDEVICES -ne 1 ]; then
echo $NUMUSBDEVICES USB devices are connected, but it must be only 1 device.
exit 1
fi
USBDEVICE=$(ls /dev/disk/by-id/usb* -1 | xargs readlink -f | grep -E '[a-z]+$')
echo $USBDEVICE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment