getopt man page on Ultrix

Man page or keyword search:  
man Server   3690 pages
apropos Keyword Search (all sections)
Output format
Ultrix logo
[printable version]

getopt(3)							     getopt(3)

Name
       getopt - get option letter from argument vector

Syntax
       #include <stdio.h>
       int getopt (argc, argv, optstring)
       int argc;
       char ∗∗argv;
       char ∗optstring;

       extern char ∗optarg;
       extern int optind, opterr;

Description
       The  subroutine	returns	 the next option letter in argv that matches a
       letter in optstring.  The optstring is a string	of  recognized	option
       letters;	 if a letter is followed by a colon, the option is expected to
       have an argument that may or may not be	separated  from	 it  by	 white
       space.	The optarg is set to point to the start of the option argument
       on return from

       The function places in optind the argv index of the next argument to be
       processed.   The	 external variable optind is automatically initialized
       to 1 before the first call to

       When all options have been processed (that is, up  to  the  first  non-
       option  argument),  returns  EOF.  The special option -- may be used to
       delimit the end of the options; EOF will be returned, and  --  will  be
       skipped.

Diagnostics
       The  function  prints an error message on stderr and returns a question
       mark (?)	 when it encounters an option letter that is not  included  in
       optstring.  Setting opterr to 0 disables this error message.

Examples
       The  following  code fragment shows how one might process the arguments
       for a command that can take the mutually exclusive options a and b, and
       the options f and o, both of which require arguments:
       #include <stdio.h>
       main (argc, argv)
       int argc;
       char ∗∗argv;
       {
	      int c;
	      extern int optind, opterr;
	      extern char ∗optarg;
	      .
	      .
	      .
	      .
	      while ((c = getopt (argc, argv, "abf:o:")) != EOF)
		       switch (c) {
		       case 'a':
			       if (bflg)
				       errflg++;
			       else
				       aflg++;
			       break;
		       case 'b':
			       if (aflg)
				       errflg++;
			       else
				       bproc( );
			       break;
		       case 'f':
			       ifile = optarg;
			       break;
		       case 'o':
			       ofile = optarg;
			       bufsiza = 512;
			       break;
		       case '?':
			       errflg++;
		       }
	       if (errflg) {
		       fprintf (stderr, "usage: . . . ");
		       exit (2);
	       }
	       for ( ; optind < argc; optind++) {
		      if (access (argv[optind], 4)) {
	       .
	       .
	       .
       }

See Also
       getopt(1)

								     getopt(3)
[top]

List of man pages available for Ultrix

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
...................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net