Re: shell
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Tue, 28 Mar 2006 20:47:03 +0100
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
.
- Follow-Ups:
- Re: shell
- From: Geoff Clare
- Re: shell
- References:
- Prev by Date: Re: Daylight Savings? indiana
- Next by Date: Conference Proceedings
- Previous by thread: Re: shell
- Next by thread: Re: shell
- Index(es):
Relevant Pages
|