delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/01/23/10:04:34

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
From: "Markus Hoenicka" <Markus DOT Hoenicka AT uth DOT tmc DOT edu>
MIME-Version: 1.0
Message-ID: <14957.40803.113000.724225@gargle.gargle.HOWL>
Date: Tue, 23 Jan 2001 15:12:35 +0000 (CT0)
To: cygwin AT cygwin DOT com
Subject: using of getopts in bash
In-Reply-To: <C9A98ED35114D31197D000805FEA668E027B1889@mucexch.muc.sdm.de>
References: <C9A98ED35114D31197D000805FEA668E027B1889 AT mucexch DOT muc DOT sdm DOT de>
X-Mailer: VM 6.75 under Emacs 20.6.1

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;;
  esac
done

# correct the index so the filename argument is always $1
shift $(($OPTIND - 1))

klaus DOT berndl AT sdm DOT de 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)
Markus DOT Hoenicka AT uth DOT tmc DOT edu
http://ourworld.compuserve.com/homepages/hoenicka_markus/


--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019