On Thu, Sep 16, 2010 at 01:10:33PM -0700, Juli Mallett wrote: > On Thu, Sep 16, 2010 at 04:36, Bruce Evans <b...@optusnet.com.au> wrote: > > WHat about the lesser burder on a character or two for putting -- in the > > synopsis where it is more visible:
> > printf [--] format [arguments ...] > Right, that's what I've been thinking about. For that matter, does > printf(1) need to use getopt(3) at all? It seems like simply checking > for "--" could be sufficient. Does POSIX require that it exit with an > error if it's given any options? It does not: implementations may add options as an extension and future versions of POSIX may add options. So while it would be a valid extension to allow format strings starting with "-" without "--" protection (other than "--" itself), I think it would be unwise. Most implementations of printf(1), other than the zsh builtin, require "--" protection for format strings starting with "-". Some of them also accept a few options: ksh93's builtin and GNU coreutils accept common options like --help, bash's builtin has a -v option to write the output directly into a variable (which seems bad to me by the way; I think printf(1) should usually be a builtin but it should be possible to use an external version with only performance and ARG_MAX as downsides). It is preferable if attempts to use such options fail loudly rather than silently writing garbage. I do not like "frivolous" extensions either, extensions that cause scripts written for FreeBSD to break on other systems without a good reason. Also note that the strict treatment of "-" is possible because printf(1) has historically recognized and required "--". Utilities that have not historically recognized "--" such as most of the special builtins may need a weaker approach. For example, in -current I have changed . and exec to treat "--" specially but not any other string starting with "-". The strict approach is cleaner but may cause compatibility problems in those cases. > At the very least, it seems like it would be more productive to have > printf(1) give unusually-helpful error messages (perhaps merely > changing its usage output to match that synopsis) if it encounters a > string beginning with '-' other than "--". That would be acceptable. -- Jilles Tjoelker _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"