05 引数の取得(getopts)

http://d.hatena.ne.jp/taiyo/20080211/p1

#!/bin/bash

usage_exit() {
        echo "Usage: $0 [-s LV splite size] [-c LV splite count] [-v VG name] [-a Action]..." 1>&2
        exit 1
}

while getopts s:c:v:a: opts
do
    case $opts in
        s)  _size=$OPTARG
            ;;
        c)  _count=$OPTARG
            ;;
        v)  _vg_name=$OPTARG
            ;;
        a)  _action=$OPTARG
            ;;
        \?) usage_exit
            ;;
    esac
done
shift $((OPTIND - 1))

if [ -z $_size -a -z $_count -a -z $_vg_name -a -z $_action ];then
	usage_exit
fi


echo "size=$_size count=$_count vg_name=$_vg_name action=$_action"