*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->Tru64 Unix man pages -> getopt (1)              
Title
Content
Arch
Section
 

getopt(1)

Contents


NAME    [Toc]    [Back]

       getopt - Parses command line flags and arguments

SYNOPSIS    [Toc]    [Back]

       getopt format tokens

DESCRIPTION    [Toc]    [Back]

       The getopt command is used to parse a list of tokens using
       a format that specifies expected flags and  arguments.   A
       flag  is  a  single ASCII letter and, when followed by a :
       (colon), is expected to take a modifying argument that may
       or  may  not  be  separated from it by one or more tabs or
       spaces.  (You can include multi-byte characters  in  arguments,
 but not as flag letters.)

       The  getopt  command completes processing when it has read
       all tokens or when it  encounters  the  special  token  --
       (double dash).  It then outputs the processed flags, a --,
       and any remaining tokens.

       If a token fails to match a flag, getopt writes a  message
       to standard error.

NOTES    [Toc]    [Back]

       In the csh, use the following command to run getopt:

       set argv=`getopt flag_string $*`

EXAMPLES    [Toc]    [Back]

       The  following  is  an  example  of the use of getopt in a
       skeleton shell script to parse options:

       #!/bin/sh # parse  command  line  into  arguments  set  --
       `getopt  a:bc $*` # check result of parsing if [ $? != 0 ]
       then
               exit 1 fi while [ $1 != -- ] do
               case $1 in
               -a)     # set up the -a flag
                       AFLG=1
                       AARG=$2
                       shift;;
               -b)     # set up the -b flag
                       BFLG=1;;
               -c)     # set up the -c flag
                       CFLG=1;;
               esac
               shift  # next flag done  shift     #  skip  double
       dash # now do the work .  .  .

       The following are all equivalent arguments to the script:

       -a ARG -b -c -- A B C -a ARG -bc -- A B C -aARG -b -c -- A
       B C -b -c -a ARG -- A B C







SEE ALSO    [Toc]    [Back]

      
      
       Commands:  sh(1)

       Functions:  getopt(3)



                                                        getopt(1)
[ Back ]
 Similar pages
Name OS Title
ipxfargc IRIX Returns the number of command-line arguments excluding the command name
getsubopt Tru64 Parse suboption arguments from a command line
apply IRIX apply a command to a set of arguments
apply OpenBSD apply a command to a set of arguments
apply FreeBSD apply a command to a set of arguments
apply Tru64 Applies a command to a set of arguments
command Tru64 Treats command arguments as simple commands
edit Tru64 Edits a file line by line with a simplified command set
VkForkIO IRIX Command-line interface to shell command component
getopts Tru64 Parses utility options
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service