#!/bin/sh -u # Output a list of partitions and types for a given disk letter # ------------------------------------------------------------------ # Syntax: $0 disk_letter # ------------------------------------------------------------------ # Purpose: Output a list of partitions and types for the given disk letter. # Validate the input first. (see script_style.txt) # Bug: If the partition type is longer than 3 words, we don't output it all. # ------------------------------------------------------------------ # # Comment: many required comments are missing from this sample solution # ------------------------------------------------------------------ # standard search path plus system maintenance path too PATH=/bin:/usr/bin:/sbin ; export PATH umask 022 LC_COLLATE=C ; export LC_COLLATE # input argument count validation (required) if [ $# -ne 1 ] ; then echo 1>&2 "$0: Expecting one disk letter argument, found $# ($*)" exit 1 fi letter="$1" # more input validation (not required) if [ "$letter" = "" ] ; then echo 1>&2 "$0: Disk drive letter is empty; nothing done" exit 1 fi drive="/dev/hd$letter" echo "Using disk drive letter '$letter' and drive '$drive'" # drive target validation (required) if [ ! -e "$drive" ] ; then echo 1>&2 "$0: Disk drive '$drive' does not exist" exit 1 fi # processing and output; remove the boot flag asterisk if part=$( sfdisk -l "$drive" ) ; then echo "$part" | grep "^$drive" | tr '*' ' ' | awk '{print $1, $7,$8,$9}' else status=$? echo 1>&2 "$0: drive '$drive': status $status: cannot list with sfdisk" exit $status fi