Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Sh shell script problem on OSF4.0 (but not on SGI) (getopts and shift)
@ 1997-05-21  4:00 Maximillien Lincourt
  1997-05-28  4:00 ` Bob Vickers
  0 siblings, 1 reply; 4+ messages in thread
From: Maximillien Lincourt @ 1997-05-21  4:00 UTC (permalink / raw)



I'm trying to use the getopts argument parser in a sh shell script, on 
DEC's OSF1 (4.0 and on SGI 6.x) but I seem to be having some soft of 
problems using it. It seems that the getopts does not get called! is the 
man page wrong or there's something I don't understand, could it be that 
getopts path is wrong ?  

There's also a problem with the shift  command, is the syntax correct
with all the parentheses on the sh man page on SGI they use 

shift `expr $OPTIND - 1`

instead of  which does not work on DEC either 

shift $(($OPTIND - 1))

I tried the exemple in the DEC's man pages which is (does not work on 
DEC or SGI (getopts on DEC and shift on SGI):


            aflag=
            bflag=
            while getopts ab: name
            do
                 case $name in
                 a)  aflag=1;;
                 b)  bflag=1
                     bval="$OPTARG";;
                 ?)  printf "Usage: %s: [-a] [-b value] args\n" $0
                     exit 2;;
                 esac
            done
            if [ ! -z "$aflag" ]; then
                 printf "Option -a specified\n"
            fi
            if [ ! -z "$bflag" ]; then
                 printf 'Option -b "%s" specified\n' "$bval"
            fi
            shift $(($OPTIND - 1))
            printf "Remaining arguments are: %s\n" "$*"


on SGI the example is (and it's working on SGI but not on DEC 
(shift problem!)

          while getopts abo: c
          do
               case $c in
               a | b)    FLAG=$c;;
               o)        OARG=$OPTARG;;
               \?)       echo $USAGE
                         exit 2;;
               esac
          done
          shift `expr $OPTIND - 1`


        Thanks for any help!



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Sh shell script problem on OSF4.0 (but not on SGI) (getopts and shift)
  1997-05-21  4:00 Sh shell script problem on OSF4.0 (but not on SGI) (getopts and shift) Maximillien Lincourt
@ 1997-05-28  4:00 ` Bob Vickers
  1997-05-28  4:00   ` Chet Ramey
  0 siblings, 1 reply; 4+ messages in thread
From: Bob Vickers @ 1997-05-28  4:00 UTC (permalink / raw)
  To: Maximillien Lincourt


Maximillien Lincourt wrote:
> 
> I'm trying to use the getopts argument parser in a sh shell script, on
> DEC's OSF1 (4.0 and on SGI 6.x) but I seem to be having some soft of
> problems using it. It seems that the getopts does not get called! is the
> man page wrong or there's something I don't understand, could it be that
> getopts path is wrong ?
> 
> There's also a problem with the shift  command, is the syntax correct
> with all the parentheses on the sh man page on SGI they use
> 
> shift `expr $OPTIND - 1`
> 

As far as I can make out, /bin/getopts is a total waste of space,
written by someone who doesn't know the first law of Unix programming:
"A Unix process cannot alter the environment of its parent".

getopts has to be a shell built-in command, otherwise it won't work. ksh
has it, bash has it and many implementations of sh have it.

Change the first line of your script to #!/bin/ksh
and you should begin to get consistent behaviour between SGI and DEC.

Any comments from DEC about this?

Bob
-- 
======================================================================
Bob Vickers			R.Vickers@rhbnc.ac.uk
Dept of Computer Science, Royal Holloway College, University of London
WWW:	http://www.dcs.rhbnc.ac.uk/%7Ebobv/
Phone:	+44 1784 443691



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Sh shell script problem on OSF4.0 (but not on SGI) (getopts and shift)
  1997-05-28  4:00 ` Bob Vickers
@ 1997-05-28  4:00   ` Chet Ramey
  1997-06-09  4:00     ` David Boyce
  0 siblings, 1 reply; 4+ messages in thread
From: Chet Ramey @ 1997-05-28  4:00 UTC (permalink / raw)



In article <338BF0E4.41C6@dcs.rhbnc.ac.uk>,
Bob Vickers  <bobv@dcs.rhbnc.ac.uk> wrote:

>As far as I can make out, /bin/getopts is a total waste of space,
>written by someone who doesn't know the first law of Unix programming:
>"A Unix process cannot alter the environment of its parent".

Don't be so harsh.  I assume that DEC is attempting to conform to the
letter of POSIX.2, which requires that certain `regular' builtins
(of which `getopts' is one) ``be implemented in a manner so that
they can be accessed via the POSIX.1 exec family of functions.''

POSIX.2 doesn't say they have to be useful, but they must be available.
For your amusement, `read', `cd', `alias' and the job control builtins
(fg/bg/jobs) must also be present in the file system as executables.
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, Case Western Reserve University	Internet: chet@po.CWRU.Edu



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Sh shell script problem on OSF4.0 (but not on SGI) (getopts and shift)
  1997-05-28  4:00   ` Chet Ramey
@ 1997-06-09  4:00     ` David Boyce
  0 siblings, 0 replies; 4+ messages in thread
From: David Boyce @ 1997-06-09  4:00 UTC (permalink / raw)



Chet Ramey wrote:
> 
> In article <338BF0E4.41C6@dcs.rhbnc.ac.uk>,
> Bob Vickers  <bobv@dcs.rhbnc.ac.uk> wrote:
> 
> >As far as I can make out, /bin/getopts is a total waste of space,
> >written by someone who doesn't know the first law of Unix programming:
> >"A Unix process cannot alter the environment of its parent".
> 
> Don't be so harsh.  I assume that DEC is attempting to conform to the
> letter of POSIX.2, which requires that certain `regular' builtins
> (of which `getopts' is one) ``be implemented in a manner so that
> they can be accessed via the POSIX.1 exec family of functions.''
> 
> POSIX.2 doesn't say they have to be useful, but they must be available.
> For your amusement, `read', `cd', `alias' and the job control builtins
> (fg/bg/jobs) must also be present in the file system as executables.
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> 
> Chet Ramey, Case Western Reserve University     Internet: chet@po.CWRU.Edu

Yes, I was involved in the POSIX compliance effort at OSF and this is
exactly the case. POSIX requires that these commands be exec-able so we
put a little ksh script in /usr/bin which would run the ksh builtin of
the same name, and then placed links to it by names such as /usr/bin/cd,
/usr/bin/getopts, etc. Trust me, we were perfectly well aware of the
ridiculous nature of what we were doing. I can't speak for
implementations other than OSF/1 but presumably other vendors, at least
those who were as obsessive about standards as we were, did similar
things.

David



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-06-09  4:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-05-21  4:00 Sh shell script problem on OSF4.0 (but not on SGI) (getopts and shift) Maximillien Lincourt
1997-05-28  4:00 ` Bob Vickers
1997-05-28  4:00   ` Chet Ramey
1997-06-09  4:00     ` David Boyce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox