Monday, November 16, 2009

structured script

a good sample of user interaction script,functioned and structured.

#!/bin/bash

usage(){
echo "Usage: $0 {-a arg1} {-b arg2}" #variable if needed
exit 1
}
option1(){
echo "you pick option 2,add your script here"
}
option2(){
echo "you pick option 2,add your script here"
}

while getopts a:b:h option
do
case "${option}"
in
a) option1 ${OPTARG};; #variable/arg passing with ${OPTARG}
b) option2 ${OPTARG};;
\?) usage
exit 1;;
esac
done

0 Comment :