From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,e59632480a891a96,start X-Google-Attributes: gidfee84,public From: mark@cita.toronto.edu (Mark Bartelt) Subject: How (if at all) does one use "getopts" with /bin/sh? Date: 1998/02/19 Message-ID: #1/1 X-Deja-AN: 326589879 Sender: nntp@utcc.utoronto.ca (News) X-Nntp-Posting-Host: rorqual.cita.utoronto.ca Organization: Canadian Institute for Theoretical Astrophysics Reply-To: mark@cita.utoronto.ca Newsgroups: comp.unix.osf.osf1 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