Subject: Re: 1.4.1 sh's backquoted getopts doesn't work
To: None <Erich.T.Enke@wheaton.edu>
From: John Darrow <John.P.Darrow@wheaton.edu>
List: netbsd-help
Date: 02/03/2000 15:22:40
In article <Pine.NEB.4.21.0002031349130.25572-100000@scilab13.wheaton.edu>,
Erich T. Enke <Erich.T.Enke@wheaton.edu> wrote:
>Subject pretty much says it.  In 1.3.3, `getopts ab:c var` works as
>expected, but in 1.4.1, getopts ab:c var works whereas `getopts ab:c var`
>doesn't.

Actually, it works as documented.  From sh(1):

   Command Substitution
     Command substitution allows the output of a command to be substituted in
     place of the command name itself.  Command substitution occurs when the
     command is enclosed as follows:

           $(command)

     or (``backquoted'' version):

           `command`

     The shell expands the command substitution by executing command in a sub-
     shell environment and replacing the command substitution with the stan-
     dard output of the command, removing sequences of one or more <newline>s
     at the end of the substitution.  (Embedded <newline>s before the end of
     the output are not removed; however, during field splitting, they may be
     translated into <space>s, depending on the value of IFS and quoting that
     is in effect.)

Thus, any changes to the environment within the backquotes (such as getopts)
are restricted to that subshell, and do not propogate to the calling shell.

1.3.3 is actually broken in this regard, 1.4.1 is fixed.

jdarrow

-- 
John Darrow - Senior Technical Specialist               Office: 630/752-5201
Computing Services, Wheaton College, Wheaton, IL 60187  Fax:    630/752-5968
Alphapage: 6303160707@alphapage.airtouch.com            Pager:  630/316-0707
Email:     John.P.Darrow@wheaton.edu