#! /bin/sh

# Question 4, shell programming assignment, 2003.

prog=`basename $0`
usage() {
   echo "Usage: $prog [-s] [-l] dir..."
   echo "print disk usage of each directory"
   echo -- "-s smallest first"
   echo -- "-l largest first"
   exit 1
}

SORTBY=largest_first
while getopts ":sl" opt
do
    case $opt in
        s) SORTBY=smallest_first ;;
        l) SORTBY=largest_first  ;;
        *) usage                 ;;
    esac
done
shift $((OPTIND - 1))

SORTOPT=-r
if [ "$SORTBY" = "smallest_first" ]; then
    SORTOPT=
fi

du -s "$@" | sort -n ${SORTOPT}
