🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs.usg
Article #275

getopt(1) doesn't/can't preserve quoted args

#275
From: ptw
Date: Mon, 17 Feb 1986 17:07
17 lines
1307 bytes
As described in the man page, getopt(1) will erroneously be passed arguments
if any contain embedded IFS characters.  The correct invocation of getopt
should be:

	set -- `getopt <optstring> "$@"`

to preserve quoted args.  Unfortunately, getopt itself does not preserve
quoting.  The only "legitimate" way I could think of enhancing getopt to
preserve quoted args would be for it to single-quote each element of
its output string, requiring the following usage:

	eval set -- `getopt <optstring> "$@"`

Perhaps the re-quoting could be triggered by a quote char in optstring.

Q:  Does anyone use getopt?  Have they run into this problem?  Can anyone
suggest a better solution?
Technical Details
Message-ID: <152@babel.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!wanginst!vaxine!encore!babel!ptw

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site babel.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!wanginst!vaxine!encore!babel!ptw
From: ptw@babel.UUCP
Newsgroups: net.bugs.usg
Subject: getopt(1) doesn't/can't preserve quoted args
Message-ID: <152@babel.UUCP>
Date: Mon, 17-Feb-86 12:07:59 EST
Article-I.D.: babel.152
Posted: Mon Feb 17 12:07:59 1986
Date-Received: Fri, 21-Feb-86 04:47:02 EST
Reply-To: ptw@encore.UUCP (P. Tucker Withington)
Distribution: net
Organization: Encore Computer Corp.
Lines: 18
Keywords: getopt