using of getopts in bash

Markus Hoenicka
Tue Jan 23 07:00:00 GMT 2001

Some real-world example:

# read the command line options
while getopts ":d:hi:p:t:" opt; do
  case $opt in
    d  ) stylesheet=$OPTARG;;
    h  ) echo "creates formatted output from a DocBook SGML source"
	 echo 'usage: dbjade [-d style] [-h] [-i name] [-p prefix] [-t outformat] file1 [file2...]'
	 echo "Options: -d select stylesheet (d=default, m=m4, s=dbslide)"
	 echo "         -h print this help and exit"
	 echo "         -i set variable name in OpenJade"
	 echo "         -p use prefix for output filenames"
	 echo "         -t select the output format. Possible values are html,"
	 echo "            rtf, dvi, pdf, ps, tex, tps, tpdf. Default is tex."
	 exit 0 ;;
    i  ) includearg="-i "$OPTARG;;
    p  ) prefix=$OPTARG;;
    t  ) outformat=$OPTARG;;
    \? ) echo 'usage: dbjade [-d style] [-h] [-i name] [-p prefix] [-t outformat] file1 [file2...]'
	 echo 'type dbjade -h to invoke help'
	 exit 1;;

# correct the index so the filename argument is always $1
shift $(($OPTIND - 1)) writes:
 > Has anybody an easy understanding example for me how to use the bash build in command "getopts"
 > (or where i can find such an example)?? This would help me a lot...

Markus Hoenicka, PhD
UT Houston Medical School
Dept. of Integrative Biology and Pharmacology
6431 Fannin MSB4.114
Houston, TX 77030
(713) 500-6313, -7477
(713) 500-7444 (fax)

Want to unsubscribe from this list?
Check out:

More information about the Cygwin mailing list