🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by ptw Mon, 17 Feb 1986 17:07
getopt(1) doesn't/can't preserve quoted args
#275
Author: 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?
Re: getopt(1) doesn't/can't preserve quoted args
#277
Author: Doug Gwyn
Date: Mon, 03 Mar 1986 07:39
17 lines
1498 bytes
In a paper entitled "An Enhanced Getopt", T. C. Jones and L. A. Kennedy
of AT&T Bell Laboratories undertook an overhaul of getopt(1) and getopt(3C)
to support the Command Syntax Standard.  They proposed altering the usage
of getopt(1) from the current
	set -- `getopt ops $*`
to
	eval set -- "`getopt ops "$@"`"
in order to avoid the extra IFS argument splitting.  In order for this
proposal to work, a shell bug (handing of $@ when no arguments exist)
needs to be fixed.

Their proposal has one serious design botch, however:  The new form of
getopt(1) cannot be upward-compatible with the current version!  This
should be avoided by calling the new utility something like "getopts"
while continuing to provide a "getopt" with the old semantics during a
transition period.  I hope this mistake is fixed before we all end up
having our existing shell scripts break on "flag day".
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads