Argument checking and parsing in scripts
display_usage() {
echo "Not enough args specified. Plese specify 1) sampleId and 2)bamfile"
echo -e "\nUsage:\n$(basename "$0") [args] {sampleId} {bamfile} [optional args] {targetfile}\n"
}
if [ $# -lt 2 ];then
display_usage
exit 1
fi
Use flags to
makereport -u jsmith -p notebooks -d 10-20-2011 -f pdf
# colon after flag indicates obligatory args, without are optional
while getopts u:d:p:f: option
do
case "${option}"
in
u) USER=${OPTARG};;
d) DATE=${OPTARG};;
p) PRODUCT=${OPTARG};;
f) FORMAT=${OPTARG};;
esac
done