[SLL] script interpreter bootstrap tricks
Ted Stern
dodecatheon at gmail.com
Tue Apr 1 11:49:40 PDT 2008
Everyone knows that you start a vanilla Bourne shell script with a
shebang:
#!/bin/sh
But what do you do if you want to interpret the script with some tool,
like perl, python, tclsh or even bash, that is either not installed in
/bin or is not listed in /etc/shells? And it may not be located in
the default path, so "#!/usr/bin/env <utility>" won't work.
My goal is to have a single script that can work on several different
known OS's / configurations.
With perl, for example, I can handle my range of setups using this
bootstrap header:
#!/bin/ksh -p
printf "Hello from ksh!\n";
type perl 1>/dev/null 2>&1 && eval 'exec perl -x -wS $0 ${1+"$@"}';
[ -x /opt/open/open/bin/perl ] && eval 'exec /opt/open/open/bin/perl -x -wS $0 ${1+"$@"}';
[ -x /usr/freeware/bin/perl ] && eval 'exec /usr/freeware/bin/perl -x -wS $0 ${1+"$@"}';
[ -x /usr/local/bin/perl ] && eval 'exec /usr/local/bin/perl -x -wS $0 ${1+"$@"}';
[ -x /usr/bin/perl ] && eval 'exec /usr/bin/perl -x $0 -wS ${1+"$@"}';
[ -x /bin/perl ] && eval 'exec /bin/perl -x $0 -wS ${1+"$@"}';
exit 1;
# =======================================================================
#!/usr/bin/perl -w
# The real Perl section of the script starts below:
use strict;
# ...
BTW, I like to use ksh -p because it inhibits a Korn-shell user's
startup files, which get loaded by default /bin/sh on some systems
(surprise!).
I want to do the same kind of thing with bash: start up with
"#!/bin/ksh -p", but then track down the path for bash and re-exec the
script using that path.
Background: One of my non-Linux systems has a non-standard bash
location. But I want my script to work on both Linux and this other
non-standard *nix. Unfortunately, that non-standard bash path is not
in the default path, even though it is listed in /etc/shells. I want
the script to be the same on several different systems, because I'm
installing it via version control checkout.
While I'm on the general subject, is there any other bootstrap for
python other than
#!/usr/bin/env python
? It sometimes happens that /usr/bin/env is neither in the path nor
listed in /etc/shells, so this won't work everywhere.
Maybe the solution is to use the perl bootstrap to startup
bash/python/whatever. Yuck.
Ted
--
dodecatheon at gmail dot com
Frango ut patefaciam -- I break so that I may reveal
More information about the linux-list
mailing list