<?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 help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-help/m-p/3578342#M702877</link>
    <description>getopts doesn't test for required options.&lt;BR /&gt;&lt;BR /&gt;you'll need to test for that yourself.  something like this:&lt;BR /&gt;&lt;BR /&gt;tardir=&lt;BR /&gt;instdir=&lt;BR /&gt;&lt;BR /&gt;while getopts :d:i:u OPTION&lt;BR /&gt;do&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;if [ -z "$tardir" ] ;then&lt;BR /&gt;print -u2 "$program: tardir is unspecified"&lt;BR /&gt;usage&lt;BR /&gt;exit 2&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;probably best to test for the existance of the directories also, [ ! -d "$tardir" ] &lt;BR /&gt;</description>
    <pubDate>Thu, 07 Jul 2005 23:13:56 GMT</pubDate>
    <dc:creator>curt larson_1</dc:creator>
    <dc:date>2005-07-07T23:13:56Z</dc:date>
    <item>
      <title>getopts help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-help/m-p/3578341#M702876</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am using the following script:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;program="${0:##*/}"&lt;BR /&gt;&lt;BR /&gt;function usage {&lt;BR /&gt;echo "USAGE: $program [-d tardir -i instdir | -u]"&lt;BR /&gt;echo "d - message."&lt;BR /&gt;echo "i - message."&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;while getopts :d:i:u OPTION&lt;BR /&gt;do&lt;BR /&gt;case "$OPTION" in&lt;BR /&gt;d) tardir="$OPTARG";;&lt;BR /&gt;i) instdir="$OPTARG";;&lt;BR /&gt;u) usage;exit;;&lt;BR /&gt;:) print -u2 "$program: $OPTARG is missing argument!"&lt;BR /&gt;usage&lt;BR /&gt;exit 1;;&lt;BR /&gt;\?) print -u2 "$program: $OPTARG is an invalid option!"&lt;BR /&gt;usage&lt;BR /&gt;exit 1;;&lt;BR /&gt;esac&lt;BR /&gt;done&lt;BR /&gt;shift $(( $OPTIND - 1 ))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The issue is that I don't get any message when I just use:&lt;BR /&gt;&lt;BR /&gt;"program" &lt;NO arguments=""&gt;&lt;BR /&gt;&lt;BR /&gt;I want it to give a message that arguments are needed to execute the program.&lt;BR /&gt;&lt;BR /&gt;I get some message when I use an incorrect argument.&lt;BR /&gt;&lt;BR /&gt;Please help.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Pat&lt;/NO&gt;</description>
      <pubDate>Thu, 07 Jul 2005 19:43:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-help/m-p/3578341#M702876</guid>
      <dc:creator>Pat Peter</dc:creator>
      <dc:date>2005-07-07T19:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: getopts help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-help/m-p/3578342#M702877</link>
      <description>getopts doesn't test for required options.&lt;BR /&gt;&lt;BR /&gt;you'll need to test for that yourself.  something like this:&lt;BR /&gt;&lt;BR /&gt;tardir=&lt;BR /&gt;instdir=&lt;BR /&gt;&lt;BR /&gt;while getopts :d:i:u OPTION&lt;BR /&gt;do&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;if [ -z "$tardir" ] ;then&lt;BR /&gt;print -u2 "$program: tardir is unspecified"&lt;BR /&gt;usage&lt;BR /&gt;exit 2&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;probably best to test for the existance of the directories also, [ ! -d "$tardir" ] &lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2005 23:13:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-help/m-p/3578342#M702877</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-07-07T23:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: getopts help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getopts-help/m-p/3578343#M702878</link>
      <description>There are several ways to do this but most common is to simply test ${#} after the ${OPTIND} shift at the end of the getopts processing case statement.&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;if [[ ${#} -lt 1 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "Required arguments missing" &amp;gt;&amp;amp;2&lt;BR /&gt;    exit 255&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;When multiple arguments are required one technique is to initialize a flag variable to zero and then set this flag variable to non-zero in the getopts case statement. At the end of the case, you make sure that all of these corresponding flag variables are non-zero.&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2005 23:20:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getopts-help/m-p/3578343#M702878</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-07-07T23:20:32Z</dc:date>
    </item>
  </channel>
</rss>

