[ksh93-integration-discuss] printf syntax and /sbin/shcompatibility
Roland Mainz
roland.mainz at nrubsig.org
Sun Feb 17 17:25:56 PST 2008
Shawn Walker wrote:
> On Feb 7, 2008 11:13 PM, David Korn <dgk at research.att.com> wrote:
> > cc: swalker at opensolaris.org
> > Subject: Re: [ksh93-integration-discuss] printf syntax and /sbin/sh compatibility
> > > I just ran into an odd behaviour tonight (see bug
> > > http://defect.opensolaris.org/bz/show_bug.cgi?id=502).
> > >
> > > The following script:
> > >
> > > printf "\n----------------------\n"
> > > printf " IP configuration \n"
> > > printf "----------------------\n\n"
> > >
> > > ...works under ye olde /sbin/sh (bourne shell), but fails with
> > > "unknown option" under ksh93.
> > >
> > > Since I'm rather daft about some nuances of shell syntax, can someone
> > > explain this to me?
[snip]
> >
> > This is not a defect. If the first argument a command begins with a -
> > it is treated as an option, not an argument. The operand -- indicates
> > end of options.
> >
> > Change
> > printf "----------------------\n\n"
> > to
> > printf -- "----------------------\n\n"
>
> In this case, it isn't a script I wrote.
>
> It's part of a shell script that is used during a driver install for a
> Marvell Yukon Gigabit Ehternet Adapter.
>
> Sadly, Solaris' version of bourne shell? /sbin/sh allows the "bad
> syntax" I mentioned above.
Erm, the issue is not related to /sbin/sh. The Bourne shell (= /sbin/sh)
just has no built-in "printf" command and uses /usr/bin/printf
> I wonder if some sort of compatibility mode can be achieved for
> bourne's printf syntax.
Erm... $ man -s1 printf # says:
-- snip --
ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|_________________________|_____________________________|
| Availability | SUNWloc |
|_________________________|_____________________________|
| CSI | enabled |
|_________________________|_____________________________|
| Interface Stability | Standard |
|_________________________|_____________________________|
-- snip --
I'll try some analysis (Don Cragun may correct me):
The "interface stabilty" is defined as "Standard", e.g. /usr/bin/printf
should be "standards conforming". Since
http://www.opengroup.org/onlinepubs/009695399/utilities/printf.html does
not list any exception in argument handling for the "printf" utilty the
normal rules for argument parsing apply (see
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap01.html)
- which require that "printf" just be able to handle options and treat
arguments which start with a '-' character as options (if they are
before an argument with the value "--").
AFAIK the current behaviour of Solaris's /usr/bin/printf is therefore a
bug (and per Knut Reiner's comment in
http://defect.opensolaris.org/bz/show_bug.cgi?id=502 the POSIX test
suites complain about the issue).
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 7950090
(;O/ \/ \O;)
More information about the ksh93-integration-discuss
mailing list