Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: "Griff Miller II" Newsgroups: gnu.bash.bug Subject: Possible bug in getopts when required argument is not supplied Date: Fri, 13 Nov 2015 10:13:15 -0600 Lines: 85 Approved: bug-bash@gnu.org Message-ID: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: usenet.stanford.edu 1447439606 15782 208.118.235.17 (13 Nov 2015 18:33:26 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=oplink.net; s=default; h=Content-Transfer-Encoding:Content-Type:MIME-Version:To:From: Subject:Date:Message-ID; bh=w9psDXdjAPA2R878Zy13iy9PzeMdTmk079hUq/UoKC0=; b=c T0ucmNmWTp8bTdQw5dzE1R5OJaF6IaCOPft8EWaw1APavdVTMuc2aF/HPcElf1Kqy+70uwriToO3r bJ12cDK7UYCPPZrjE9K9ldQidIocdp7GLiYVbKQH+pmE4gU68QmrRt1J/sXzdnGblXqyZh7+TC5Ie LCwJM2IBwueG0sqI=; User-Agent: SquirrelMail/1.5.2 [SVN] X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cpanel1.oplink.net X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - oplink.net X-Get-Message-Sender-Via: cpanel1.oplink.net: authenticated_id: griff.miller@oplink.net X-Authenticated-Sender: cpanel1.oplink.net: griff.miller@oplink.net X-Source: X-Source-Args: X-Source-Dir: X-Filter-ID: s0sct1PQhAABKnZB5plbIT50OT5zrCXWMgnOPri5Rsyv4UAD9srRy7CsKvBiFIJUXewBu5TuhjJr gH3eyFBy7nRTh2x4czFsyWi02C6IOpqixGGqP+aNBDHPompdpVJGwnPxZ9F4epQ52HWf889wXCmC AwVgJ7O+K3F8ctOqie6/1Q5y3+zgOK0cmRWqp+hmXPWlFdaGOH191uXjgjQN/ZW/ux/C+1BT4XrA ZnOFvpmzxQlbngCLuJt576uaV4jSCrfVQmylutQTt5q+2gt0CIHElz4uuB1vUyx2xNcRnLAAObiP uFHBBo76mqNjlusTVgQ2dYQJ3VWrUdOP3MyWJ+/zQGLR6FNUcSp4kI1exRngOQHTwtOQMdChmanG UmeK/OL5JjK+M3G1xdmtrmYEFmWyisqb9EBCbrK+u2DaLBcaVYuvXXjnIQ9UbG2xl1SQsFdeAnz4 j2Jd9hHlkVeQ3ZgkN3eey6+2LcwPX57eiWBOuAjQzRJZPWVEwiTZ70tVRl8FMkZlwD1OT/TKB30H PoPAgTtUp75uqlx0KezvZHXcTpDdTRT2pNnAQUecKNzSgwGuXf/RcrjZvMON2cBP6miH1Wgh6RAe nBR+licROGaIMuHQ7Q0ctlj27TjTmXwnyD6nLxIlEdMQkjmuVF4WmbbU1LZIPOttXZ/5N7yxhWh4 VIDKaD4XDqKjHHRLJLgz X-Report-Abuse-To: spam@filter01.reliabledns.org X-Filter-Fingerprint: IFrWXGses7OKB5S5G8/dJUb3OPwsHaH0Fvg5oXltHd9A3cTUQ1R++keuE7RDJ8Kg3RbMLUalw1oC mj99/u+PoqoVy8a3lsStJtAvpObFX0Wok1JBYnOLzfRIhlEHQynLUpndEJ0YoaLytXXo8BMTaVt0 ARHRi6XGuAluI1udprFy32DUYpEhA3j9NJFmItfypuoazoDH3m92PL21GfhFYWcYmGLKZUTyGy/B A6iJtsD8WFC+rpTT4JYvoDjVeZUw3fI9smEy0EupqfCN6sn6Zg== X-Originating-IP: 216.230.224.98 X-SpamExperts-Domain: outbound.oplink.net X-SpamExperts-Username: 216.230.224.98 Authentication-Results: reliabledns.org; auth=pass smtp.auth=216.230.224.98@outbound.oplink.net X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.13) X-Recommended-Action: accept X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 199.192.217.37 X-Mailman-Approved-At: Fri, 13 Nov 2015 13:33:24 -0500 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11875 Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: cygwin Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='x86_64-unknown-cygwin' -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -DRECYCLES_PIDS -I. -I/usr/src/bash-4.3.42-4.x86_64/src/bash-4.3 -I/usr/src/bash-4.3.42-4.x86_64/src/bash-4.3/include -I/usr/src/bash-4.3.42-4.x86_64/src/bash-4.3/lib -DWORDEXP_OPTION -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/bash-4.3.42-4.x86_64/build=/usr/src/debug/bash-4.3.42-4 -fdebug-prefix-map=/usr/src/bash-4.3.42-4.x86_64/src/bash-4.3=/usr/src/debug/bash-4.3.42-4 uname output: CYGWIN_NT-6.1 MILLERIG1 2.3.0(0.291/5/3) 2015-11-09 10:24 x86_64 Cygwin Machine Type: x86_64-unknown-cygwin Bash Version: 4.3 Patch Level: 42 Release Status: release Description: getopts doesn't always detect that a required argument is not supplied. Repeat-By: Here is a test script: #!/bin/bash # Parse command-line options. c=0 opts=a:b:c while getopts $opts opt ; do case $opt in a) a=$OPTARG ;; b) b=$OPTARG ;; c) c=1 ;; ?) exit 1 ;; esac done echo a = \"${a}\" echo b = \"${b}\" echo c = $c % ./myscript -a a a = "a" b = "" c = 0 % ./myscript -a a -b ./test_bash_getopts_unsilent_reporting: option requires an argument -- b % ./myscript -a a -b b a = "a" b = "b" c = 0 % ./myscript -a -b b a = "-b" b = "" c = 0 Note that in the last run, getopts does not detect that nothing was passed via -a, even though -a requires it. Instead, it thinks the next switch (-b) is the value of -a. Perhaps this was a conscious decision, so that values starting with '-' can be passed, but it's a more of a surprise to the developer than discovering that the user can't do e.g. ./myscript -a -my_a_val . Can this bug, if it's deemed a bug, be fixed, else the manpage updated in the getopts section to make it clear what is going on? If there is a requirement that the user be able to have optargs that start with '-', maybe not allow OPTARG be one of the options in the first argument to getopts ($opts in the above script)? Thank you.