Re: shell



2006-03-28, 14:07(+01), Geoff Clare:
[...]
#! /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.

At least, sensible systems have by defaut an environment
conforming to the latest SUS they support, which is to my mind
the only sensible behaviour (if we support the next SUS version
tries to be backward compatible with the previous).

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.

As systems like Solaris have non-conformant default environment,
that's not feasible.

The way to ensure it is executed
in a conforming environment is only to execute it from a known
conforming environment.

Given that the default environment is not conforming, we need to
have a way to switch to that default environment. Otherwise,
selling a Unix conformant script is like selling a car and say
it won't work except on pink roads.

What Unix vendors agree to do is provide a
/bin/susv3-sh wrapper, that fixes the environment and starts the right
shell.

This way, one could do:

#! /bin/susv3-sh -
# use a POSIX syntax

The "fix the environment" thing would be tricky though (should
it unset ENV, bash's SHELLOPTS, ksh93's FIGNORE, cope with
locales, TZ...)

--
Stéphane
.



Relevant Pages

  • Re: shell
    ... provide you with a conforming environment. ... For a script to be fully portable to all conforming systems it ... environment variables are set among other things). ...
    (comp.unix.questions)
  • 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: Install Java 1.6
    ... Under bash the equivalent ... builtins are export and unset. ... First find out what the environment and PATH are. ...
    (alt.os.linux.suse)
  • Re: what does export do?
    ... On 5/20/05, THUFIR HAWAT wrote: ... > "Every programming language has the ability to access its environment ... > and to set or unset its variables. ...
    (Fedora)
  • Re: what does export do?
    ... On Fri, 2005-05-20 at 21:40 +0100, THUFIR HAWAT wrote: ... > "Every programming language has the ability to access its environment ... > and to set or unset its variables. ... > environment variables are stored. ...
    (Fedora)