Date: Wed, 25 Feb 1998 11:48:31 -0600 (CST) From: bob@pmr.com To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/5845: in sh, set -- `getopt ...` always returns zero Message-ID: <199802251748.LAA06639@luke.pmr.com>
next in thread | raw e-mail | index | archive | help
>Number: 5845 >Category: bin >Synopsis: in sh, set -- `getopt ...` always returns zero >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Feb 25 09:50:01 PST 1998 >Last-Modified: >Originator: Bob Willcox >Organization: Power Micro Research >Release: FreeBSD 2.2.5-STABLE i386 >Environment: FreeBSD 2.2.5-STABLE (as of Feb 22, 1998). Also fails on -current (as of Feb 4, 1998). Failure appears to be in sh. Note that pdksh (vv5.2.13) works with getopt as documented and bash (v1.14.7) behaves the same as sh. >Description: The sh always returns a zero return code from the set command used with getopt. E.g., the example in the getopt man page does not work since errors in flags/options will not result in a non zero return code from the set command in: set -- `getopt abo: $*` if test $? != 0 then echo 'Usage: ...' exit 2 fi ... Consequently, the subsequent if will never be true. Seems either the sh set command should be fixed to work as documented in the getopt manpage or the example should be updated to something that does work. >How-To-Repeat: Run this #!/bin/sh set -- `getopt d:v $*` echo "set return code = $?" and notice that even with unrecognized flags the return code from the set statement is zero. >Fix: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199802251748.LAA06639>