Re: #! -- reconsideration?
Dan Kegel wrote:
>
> Don Cragun wrote:
> > The POSIX standards and the Single UNIX Specifications have
> > wisely chosen not to specify hard coded pathnames for the standard
> > utilities. Implementations need to give users a description of how to
> > find the set of utilities specified by the standards they support, and
> > the standards need to specify how to find the rest of the standard
> > utilities once you get to that point (such as Austin Group revision
> > draft 3 XCU's
> > -v specification PATH
> > command.) Then applications that want to use #! have to be configured
> > to find the absolute pathname for the utility they want invoked as the
> > interpreter by #! as part of their installation processing.
>
> So you're proposing that a package that wants to be portable will
> rewrite all of its shell scripts at install time and replace the thing
> following #! with the absolute path to the POSIX-compliant shell
> located in the first directory listed in `getconf PATH`?
>
> That's reasonable, I suppose, but it's not something I've seen done
> in practice yet. Has anyone else observed this in the wild?
Attached is the relevant fragment from perl's Configure that determines
what the first line should be. It is written in bourne shell.
It doesn't use getconf and works even for for non-posix systems that
require ": use" instead of "#!". nce this first line is determined,
it is saved away for later use when creating shell scripts.
______________________________________________________________________
Maurice Cinquini Senior Software Engineer
mcinquini@speedera.com Speedera Networks
Work (408) 970 1502 4800 Great America Pwky, Suite 220
Fax (408) 855 9543 Santa Clara, CA 95054-1227 USA
______________________________________________________________________
This message is for the named person(s) use only. It may contain
confidential, proprietary or legally privileged information. No
confidentiality or privilege is waived or lost by any mistransmission.
If you receive this message in error, please immediately delete it and
all copies of it from your system, destroy any hard copies of it and
notify the sender. You must not, directly or indirectly, use, disclose,
distribute, print, or copy any part of this message if you are not the
intended recipient. SPEEDERA NETWORKS, INC. reserves the right to
monitor all e-mail communications through its network.
: Find the basic shell for Bourne shell scripts
case "$sh" in
'')
case "$SYSTYPE" in
*bsd*|sys5*) xxx="/$SYSTYPE/bin/sh";;
*) xxx='/bin/sh';;
esac
if test -f "$xxx"; then
sh="$xxx"
else
: Build up a list and do a single loop so we can 'break' out.
pth=`echo $PATH | sed -e "s/$p_/ /g"`
for xxx in sh bash ksh pdksh ash; do
for p in $pth; do
try="$try ${p}/${xxx}"
done
done
for xxx in $try; do
if test -f "$xxx"; then
sh="$xxx";
break
elif test -f "$xxx.exe"; then
sh="$xxx";
break
fi
done
fi
;;
esac
case "$sh" in
'') cat <<EOM >&2
$me: Fatal Error: I can't find a Bourne Shell anywhere.
Usually it's in /bin/sh. How did you even get this far?
Please contact perlbug@perl.com and we'll try to straighten this all out.
EOM
exit 1
;;
esac
: see if sh knows # comments
if `$sh -c '#' >/dev/null 2>&1`; then
shsharp=true
spitshell=cat
xcat=/bin/cat
test -f $xcat || xcat=/usr/bin/cat
echo "#!$xcat" >try
$eunicefix try
chmod +x try
./try > today
if test -s today; then
sharpbang='#!'
else
echo "#! $xcat" > try
$eunicefix try
chmod +x try
./try > today
if test -s today; then
sharpbang='#! '
else
sharpbang=': use '
fi
fi
else
echo " "
echo "Your $sh doesn't grok # comments--I will strip them later on."
shsharp=false
cd ..
echo "exec grep -v '^[ ]*#'" >spitshell
chmod +x spitshell
$eunicefix spitshell
spitshell=`pwd`/spitshell
cd UU
echo "I presume that if # doesn't work, #! won't work either!"
sharpbang=': use '
fi
rm -f try today
: figure out how to guarantee sh startup
case "$startsh" in
'') startsh=${sharpbang}${sh} ;;
*)
esac
cat >try <<EOSS
$startsh
set abc
test "$?abc" != 1
EOSS
chmod +x try
$eunicefix try
if ./try; then
: echo "Yup, it does."
else
echo "Hmm... '$startsh' does not guarantee sh startup..."
echo "You may have to fix up the shell scripts to make sure $sh runs them."
fi
rm -f try
Reply to: