File:  [MW Coherent from dump] / coherent / a / usr / man / COHERENT / getopts
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



getopts                      Command                      getopts




Parse command-line options

ggeettooppttss _o_p_t_s_t_r_i_n_g _n_a_m_e [ _o_p_t ]

The command  ggeettooppttss is available  under the Korn kksshh  to parse a
command's  options  and  check  their legality.   _o_p_t_s_t_r_i_n_g  must
contain the  options letters that the  command using ggeettooppttss will
recognize.  If  a letter is followed by a  colon `:', that option
must have an argument that is separated from it by whitespace.

Each time it is invoked,  ggeettooppttss places the next option into the
shell  variable _n_a_m_e  and the  index of the  next argument  to be
processed into the shell variable OOPPTTIINNDD, which is initialized by
default  to one.   When an option  requires an  argument, ggeettooppttss
copies it  into the shell variable  OOPPTTAARRGG. If ggeettooppttss encounters
an error, it initializes variable _n_a_m_e to ?.

When it  encounters the  end of  the options, ggeettooppttss  exits with
non-zero  status.   The  special option  ``--''  can  be used  to
delineate the end of options.

***** Example *****

The following  example processes a command  that takes options aa,
bb, and oo; the last option requires an argument:


        while getopts abo: c
        do
                case $c in
                        a|b)    FLAGS=$FLAGS$c;;
                        o)      OARG=$OPTARG;;
                        \?)     echo $USAGE 1>&2
                                exit 2;;
                esac
        done
        shift OPTIND-1


This code will accept any of the following as equivalent:


        cmd -a -b -o "xxx z yy" file
        cmd -a -b -o "xxx z yy" -- file
        cmd -ab -o "xxx z yy" file
        cmd -ab -o "xxx z yy" -- file


***** See Also *****

ccoommmmaannddss, ggeettoopptt(), kksshh





COHERENT Lexicon                                           Page 1



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.