Re: shell



Stephane Chazelas <stephane_chazelas@xxxxxxxx> wrote, on Mon, 27 Mar 2006:

On Mon, 27 Mar 2006 13:54:09 +0100, Geoff Clare wrote: [...]
So, how do you force a XPG4 or XPG6 "conforming environment" in a
portable way? (based on a "case `uname`"?).

There is no portable way to set up a conforming environment from a
non-conforming one. (Nor could there ever be, if you think about it, as
the standards cannot place any constraint on the behaviour of
non-conforming environments).
[...]

But Solaris is meant to be conformant, isn't it? On startup, it doesn't
provide you with a conforming environment. So there has to be a way to
switch to that environment

Yes. Conforming systems must document how to set up a conforming
environment.

With Solaris 7, according to the standards(5) man page, it looks like you
only need to make sure /usr/xpg4/bin is before the other ones to be SUSv2
conformant? What about Solaris 10, then.

On Solaris 10 the same man page says you must set PATH "to specify
the directories listed in the following table in the order specified"
and the table entry for "POSIX.1-2001, SUSv3" is:

1. /usr/xpg6/bin

2. /usr/xpg4/bin

3. /usr/ccs/bin

4. /usr/bin

5. directory containing binaries for
your compiler

6. other directories containing
binaries needed by the application


So, if I want a SUSv2 conformant toolchest to interpret my script written
in a SUSv2 conformant syntax, practically, what should I write:

#! /bin/sh -
if [ "$$" != "$FIND_SH_ACK" ]; then
FIND_SH_ACK=$$ export FIND_SH_ACK
case `uname` in
SunOS)
PATH=/usr/xpg4/bin/sh:$PATH
export PATH
exec /usr/xpg4/bin/sh - "$0" ${1+"$@"} ;;
Linux)
export POSIXLY_CORRECT=1 _POSIX2_VERSION=199210 ;;
Tru64) ???;;
*) ???;;
esac
fi
unset FIND_SH_ACK

?

Yes, if you want to do that kind of thing then you need to handle
each conforming system individually. There is nothing generic you
can put for the "*) ???;;" case, so the only sensible thing to do
there is give an error message and exit.

For a script to be fully portable to all conforming systems it
should not start with #!, and should not use any hard-coded full
pathnames for standard utilities. The way to ensure it is executed
in a conforming environment is only to execute it from a known
conforming environment.

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).
The suggested method (not yet implemented) in the link you refered to:

env -i $(getconf V6_ENV) $(getconf PATH) command

(I suppose they mean
env -i -- $(getconf V6_ENV) "PATH=$(getconf PATH)" command

Environment variable names can't begin with dash, so the "--" is
unnecessary. You are right about PATH.

On which system can't environment variable names begin with "-"?

I should have said "These environment variable names ..."

The names output by getconf V6_ENV would of course have to be in
the environment variable namespace allowed to be used by the
standard utilities, as defined in XBD6 section 8.1:

"Environment variable names used by the utilities in the Shell and
Utilities volume of IEEE Std 1003.1-2001 consist solely of
uppercase letters, digits, and the '_' (underscore) from the
characters defined in Portable Character Set and do not begin with
a digit."

--
Geoff Clare <netnews@xxxxxxxxxxxxx>

.



Relevant Pages

  • Re: size_t overflow
    ... depends on implementation-defined behavior. ... on whether the result returned to the environment is considered ... of the encodings used at that interface. ... The idea of "strictly conforming" is that the program "does the ...
    (comp.std.c)
  • Re: shell
    ... unset FIND_SH_ACK ... each conforming system individually. ... As systems like Solaris have non-conformant default environment, ... selling a Unix conformant script is like selling a car and say ...
    (comp.unix.questions)
  • Re: ENV variable NOT recognized ! Reboot really necessary ????
    ... this will only change the environment block for new processes created *after* the change. ... Existing processes will keep on using their current environment block, which is the same as it was before you made the change. ... But an application needs to be written to explicitly do this; there's no mechanism in the operating system to universally update environment variables on the fly for running processes. ... For example, say you had a command prompt open, and you run a SET command to display the current variables. ...
    (microsoft.public.windowsxp.help_and_support)
  • [REVS] Using Environment for Returning Into Lib C
    ... This article explains how to use the environment variables to successfully ... The environment will consequently be used to store it. ... It is easy to write a simple program to put the command directly into the ... declare -x COLORTERM="" ...
    (Securiteam)
  • Re: SSH environment variable passing
    ... has to be a capability of both the client and the server. ... to support only a couple of specific environment variables. ... I have been told that allowing unlimited environment variables to be set ... A parallel situation exists in telnet. ...
    (SSH)