Re: shell
- From: Geoff Clare <geoff@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 28 Mar 2006 14:07:37 +0100
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.The suggested method (not yet implemented) in the link you refered to:
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).
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>
.
- Follow-Ups:
- Re: shell
- From: Stephane CHAZELAS
- Re: shell
- References:
- Prev by Date: Re: Daylight Savings? indiana
- Next by Date: Re: Daylight Savings? indiana
- Previous by thread: Re: shell
- Next by thread: Re: shell
- Index(es):
Relevant Pages
|