<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: getopts with optional parameters in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090909#M144785</link>
    <description>Hi,&lt;BR /&gt;I tried to experiment a little; perhaps you can use it...&lt;BR /&gt; &lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
    <pubDate>Mon, 13 Oct 2003 09:05:22 GMT</pubDate>
    <dc:creator>john korterman</dc:creator>
    <dc:date>2003-10-13T09:05:22Z</dc:date>
    <item>
      <title>getopts with optional parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090902#M144778</link>
      <description>I would like to use the 'getopts' command to parse my command line, but *ALL* options are optional.&lt;BR /&gt;So far I have been unable to figure out how to tell the 'getopts' command the two options which are valid e.g. 'r' &amp;amp; 'n', but that they are optional and it is valid to call the script with no options at all.&lt;BR /&gt;&lt;BR /&gt;Any suggestions?</description>
      <pubDate>Fri, 10 Oct 2003 17:58:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090902#M144778</guid>
      <dc:creator>Jaris Detroye</dc:creator>
      <dc:date>2003-10-10T17:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: getopts with optional parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090903#M144779</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;Refer to &lt;A href="http://nscp.upenn.edu/aix4.3html/cmds/aixcmds2/getopts.htm" target="_blank"&gt;http://nscp.upenn.edu/aix4.3html/cmds/aixcmds2/getopts.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;for examples to specify valid options.&lt;BR /&gt;&lt;BR /&gt;Also, refer to getopts(1) @&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/cgi-bin/fsearch/framedisplay?top=/hpux/onlinedocs/B2355-60103/B2355-60103_top.html&amp;amp;con=/hpux/onlinedocs/B2355-60103/00/01/152-con.html&amp;amp;toc=/hpux/onlinedocs/B2355-60103/00/01/152-toc.html&amp;amp;searchterms=command%7cgetopts&amp;amp;queryid=20031010-212500" target="_blank"&gt;http://docs.hp.com/cgi-bin/fsearch/framedisplay?top=/hpux/onlinedocs/B2355-60103/B2355-60103_top.html&amp;amp;con=/hpux/onlinedocs/B2355-60103/00/01/152-con.html&amp;amp;toc=/hpux/onlinedocs/B2355-60103/00/01/152-toc.html&amp;amp;searchterms=command%7cgetopts&amp;amp;queryid=20031010-212500&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Hemanth</description>
      <pubDate>Fri, 10 Oct 2003 22:32:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090903#M144779</guid>
      <dc:creator>Hemanth Gurunath Basrur</dc:creator>
      <dc:date>2003-10-10T22:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: getopts with optional parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090904#M144780</link>
      <description>'but *ALL* options are optional' --&amp;gt; what does it mean ?.... Of course, all options are optional.</description>
      <pubDate>Mon, 13 Oct 2003 02:06:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090904#M144780</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2003-10-13T02:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: getopts with optional parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090905#M144781</link>
      <description>I think you need something like&lt;BR /&gt;--&lt;BR /&gt;--&lt;BR /&gt;while getopts r:n name&lt;BR /&gt;do&lt;BR /&gt;  case ${name} in&lt;BR /&gt;      r)&lt;BR /&gt;              ...CODE TO SET "r" FLAGS HERE;;&lt;BR /&gt;      n)&lt;BR /&gt;              ...CODE TO SET "n" FLAGS HERE;;&lt;BR /&gt;      ?)&lt;BR /&gt;              ...CODE TO HANDLE INVALID OPTIONS HERE ;;&lt;BR /&gt;  esac&lt;BR /&gt;done&lt;BR /&gt;--&lt;BR /&gt;in your "...CODE" sections you can refer to ${OPTARG}, so that&lt;BR /&gt;if your program is invoked with "-r fred", then OPTARG would&lt;BR /&gt;contain "fred".&lt;BR /&gt;Hope you get the idea&lt;BR /&gt;-- Graham&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Oct 2003 02:35:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090905#M144781</guid>
      <dc:creator>Graham Cameron_1</dc:creator>
      <dc:date>2003-10-13T02:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: getopts with optional parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090906#M144782</link>
      <description>int&lt;BR /&gt;main (int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt;int c=0,rflag=0, nflag=0;&lt;BR /&gt;while (( c = getopt(argc,argv,":r:n:")) != -1 ) {&lt;BR /&gt; switch (c) {&lt;BR /&gt;      case 'r':&lt;BR /&gt;        printf("Option r chosen");&lt;BR /&gt;        rflag++;&lt;BR /&gt;        break;&lt;BR /&gt;      case 'n':&lt;BR /&gt;        printf("Option n chosen");&lt;BR /&gt;        nflag++;&lt;BR /&gt;        break;&lt;BR /&gt;      case '?':&lt;BR /&gt;        printf ("Error");&lt;BR /&gt;        break;&lt;BR /&gt;        }&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;if (rflag&amp;gt;1)&lt;BR /&gt; printf ("Error");&lt;BR /&gt;if (nflag &amp;gt;1)&lt;BR /&gt;  printf("Error");&lt;BR /&gt;Hope this helps...&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Oct 2003 04:26:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090906#M144782</guid>
      <dc:creator>Bhuvaneswari Selvaraj</dc:creator>
      <dc:date>2003-10-13T04:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: getopts with optional parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090907#M144783</link>
      <description>The problem that I see is this, if I get a '?' in the $OPTARG when either an invalid option is used, or when no options at all are used, then it is up to me to detirmine which case it is.  I was hoping that I could aviod having to do that.</description>
      <pubDate>Mon, 13 Oct 2003 08:43:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090907#M144783</guid>
      <dc:creator>Jaris Detroye</dc:creator>
      <dc:date>2003-10-13T08:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: getopts with optional parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090908#M144784</link>
      <description>YOu can examine $OPTIND, which is initialised to 1, and incremented as arguments are processed. It it is still 1, at the end of the while loop, then no arguments were processed.&lt;BR /&gt;Also, processing will drop through to the "?)" clause whenever an unexpected argument is found, ie anything except 'r', 'n'.&lt;BR /&gt;-- Graham</description>
      <pubDate>Mon, 13 Oct 2003 08:53:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090908#M144784</guid>
      <dc:creator>Graham Cameron_1</dc:creator>
      <dc:date>2003-10-13T08:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: getopts with optional parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090909#M144785</link>
      <description>Hi,&lt;BR /&gt;I tried to experiment a little; perhaps you can use it...&lt;BR /&gt; &lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
      <pubDate>Mon, 13 Oct 2003 09:05:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090909#M144785</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2003-10-13T09:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: getopts with optional parameters</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090910#M144786</link>
      <description>Graham you hit it right on the head.  That did not occur to me.  Good job, thanks.&lt;BR /&gt;&lt;BR /&gt;John, that is one approach I never thought of.  Encasing the getopts command within a case statement hmmm..... might have to try that one out sometime.&lt;BR /&gt;&lt;BR /&gt;Cudos to all!!!</description>
      <pubDate>Mon, 13 Oct 2003 10:21:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-with-optional-parameters/m-p/3090910#M144786</guid>
      <dc:creator>Jaris Detroye</dc:creator>
      <dc:date>2003-10-13T10:21:43Z</dc:date>
    </item>
  </channel>
</rss>

