* How (if at all) does one use "getopts" with /bin/sh?
@ 1998-02-19 5:00 Mark Bartelt
1998-02-19 5:00 ` Mark Bartelt
0 siblings, 1 reply; 2+ messages in thread
From: Mark Bartelt @ 1998-02-19 5:00 UTC (permalink / raw)
Sorry if I'm missing something really obvious, but ...
In other versions of UNIX (IRIX, Solaris, SunOS) "getopts" is
a shell built-in. However, the Digital UNIX /bin/sh appears
not to have it as a built-in, and /usr/bin/getopts doesn't do
the trick.
Although the manpage doesn't explicitly say so, it seems that
the DUnix "getopts" is intended to be used with ksh (and only
with ksh?), since the example includes ...
shift $(($OPTIND - 1))
However, if I make the obvious change ...
shift `expr $OPTIND - 1`
... and try using the example in a /bin/sh script, it doesn't
work (which isn't surprising, if DU's Bourne shell is lacking
the "getopts" built-in, and uses /usr/bin/getopts instead).
So ... Is there a way to use "getopts" from a /bin/sh script,
or do I need to change all the shell scripts which work fine
on all our other systems to use /bin/ksh instead?
Mark Bartelt 416/978-5619
Canadian Institute for mark@cita.utoronto.ca
Theoretical Astrophysics http://www.cita.utoronto.ca/~mark
"Nur eine Waffel taugt!" -- Parsifal, in an Eggo commercial
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How (if at all) does one use "getopts" with /bin/sh?
1998-02-19 5:00 How (if at all) does one use "getopts" with /bin/sh? Mark Bartelt
@ 1998-02-19 5:00 ` Mark Bartelt
0 siblings, 0 replies; 2+ messages in thread
From: Mark Bartelt @ 1998-02-19 5:00 UTC (permalink / raw)
Well, as is often the case, *that* one got solved quickly. Many
thanks to Paul A Sand <pas@unh.edu>, who suggested that setting
my BIN_SH environment variable to "xpg4" might make things work.
And that does it.
Also, as is often the case, the question could have been avoided
altogether with a bit more RTFM. I *did* RTFMpage for "getopts",
but it doesn't mention BIN_SH; I should have RTFMpage for /bin/sh
as well, where that environment variable is discussed. (It might
be nice if it were also mentioned in the "getopts" page.)
Anyway, thanks to Paul, and thanks in advance to all of you whose
replies haven't made it to my mailbox yet.
Mark Bartelt 416/978-5619
Canadian Institute for mark@cita.utoronto.ca
Theoretical Astrophysics http://www.cita.utoronto.ca/~mark
"Nur eine Waffel taugt!" -- Parsifal, in an Eggo commercial
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-02-19 5:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-02-19 5:00 How (if at all) does one use "getopts" with /bin/sh? Mark Bartelt
1998-02-19 5:00 ` Mark Bartelt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox