Re: shell



Stephane Chazelas <stephane_chazelas@xxxxxxxx> wrote, on Thu, 23 Mar 2006:

On Thu, 23 Mar 2006 14:39:32 +0000, Geoff Clare wrote:
Stephane Chazelas <stephane_chazelas@xxxxxxxx> wrote, on Wed, 22 Mar 2006:

# ensure `Unix' utilities
PATH=$(command -p getconf PATH; :):$PATH
export PATH

Unfortunately this method has a chicken-and-egg problem.
The output from "command -p getconf PATH" can vary depending on
whether you are running it in a conforming environment or not
(or in which conforming environment, if the system supports
multiple versions of the standard concurrently).

For example on Solaris 10, you only get the SUSv3 PATH out if
you already have PATH set to find the SUSv3 utilities before
the SUSv2 ones:

$ type sh
sh is a tracked alias for /usr/xpg4/bin/sh
$ sh -c 'PATH=/bin; command -p getconf PATH'
/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin
$ sh -c 'PATH=/usr/xpg6/bin:/usr/xpg4/bin:/bin; command -p getconf PATH'
/usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin
[...]

Thanks for pointing this out.

What would/should:

command -p env -i /usr/xpg4/bin/sh -c 'command -p getconf PATH'

return then?

and

command -p env -i PATH=/undef /usr/xpg4/bin/sh -c '
command -p getconf PATH'

As far as the standard is concerned, the behaviour is undefined.
Utilities are only required to behave as described in the standard
if they are executed in a "conforming environment" (which includes
which environment variables are set among other things).

What about:

#! /bin/sh -
[ "x$FIND_SH_HACK" = "x$$" ] ||
exec /usr/bin/env \
PATH="`/usr/bin/env -i /usr/bin/getconf PATH`:$PATH" \
FIND_SH_HACK="$$" POSIXLY_CORRECT=1 _POSIX2_VERSION=200112 \
UNIX95=1 UNIX98=1 sh - "$0" ${1+"$@"}

Is it likely to maximise the SUSv<n> conformance of the sh and
utilities on a maximum number of SUSv<n> conformant systems?

No - it doesn't work on Solaris 10, for one. If you already have
a PATH set for SUSv3 it changes it to one set for SUSv2.

By the way, there is a known issue related to whether non-standard
environment variables such as POSIXLY_CORRECT, UNIX95, etc. can be
specified as part of a system's "conforming environment". See

http://www.opengroup.org/austin/aardvark/latest/xbdbug2.txt

and search for "Enhancement Request Number 19". Current thinking is
that they can be so specified (as per current practice), and a new
feature is planned for the next POSIX revision which would allow
applications to find out which variables they need to preserve
when using "env -i".

--
Geoff Clare <netnews@xxxxxxxxxxxxx>

.



Relevant Pages

  • Re: shell
    ... The output from "command -p getconf PATH" can vary depending on ... whether you are running it in a conforming environment or not ... you already have PATH set to find the SUSv3 utilities before ...
    (comp.unix.questions)
  • Re: shell
    ... command -p getconf PATH' ... As far as the standard is concerned, ... if they are executed in a "conforming environment" (which includes ...
    (comp.unix.questions)
  • Re: shell
    ... The output from "command -p getconf PATH" can vary depending on ... whether you are running it in a conforming environment or not ... you only get the SUSv3 PATH out if ...
    (comp.unix.questions)
  • Re: shell
    ... command -p getconf PATH' ... As far as the standard is concerned, ... Utilities are only required to behave as described in the standard ... if they are executed in a "conforming environment" (which includes ...
    (comp.unix.questions)