On Mon, Jul 21, 2008,  Ryan Davis <ryand-ruby / zenspider.com> wrote:
>
> What I meant was, currently all the versions of freebsd that I use as
> well as OSX do a good job of parsing the shebang line so that options
> and/or trailing arguments are not considered part of the executable
> name. That is decidedly NOT the case on linux and a constant PITA as
> far as I'm concerned.
>
> Not all ruby command line options have any other equivalent way of
> activating their functionality. For example, while -I has
>  $:/$LOAD_PATH, -s has no analogous enabler. This means either I
> can't use the functionality or I can't use /usr/bin/env because
> it'll break on linux. :/

For what it's worth, this is what I do for a safe cross-platform way
to avoid the problem.  You could obviously skip the section on setting
a new value for PATH, but my environment is such that ruby believes
some directories in my PATH are world-writeable, when in fact they
are not.



#!/bin/sh
# -------+---------+---------+-------- + --------+---------+---------+---------+
#     /  This section is a safe way to find the interpretter for ruby,  \
#    |   without caring about the user's setting of PATH.  This reduces  |
#    |   the problems from ruby being installed in different places on   |
#    |   various operating systems.  A much better solution would be to  |
#    |   use  `/usr/bin/env -S-P' , but right now `-S-P' is available    |
#     \  only on FreeBSD 5, 6 & 7.                        Garance/2005  /
OSRUBYBIN=
for fname in /usr/local/bin /opt/csw/bin /opt/local/bin /usr/bin ; do
   if [ -x "$fname/ruby" ] ; then OSRUBYBIN="$fname/ruby" ; break; fi
done
if [ -z "$OSRUBYBIN" ] ; then
    echo "Unable to find a 'ruby' interpretter!"   >&2
    exit 1
fi
export OSRUBYBIN

#   Set a safe value for PATH here, as the cheapest way to avoid the
#   annoying ruby message:   "warning: Insecure world writable dir ..."
#   Make a copy of the user's original PATH, in case the script needs it.
PATH_PRERUBY="$PATH"
export PATH_PRERUBY
PATH="/bin:/sbin:/usr/local/bin:/usr/bin:/usr/sbin"
export PATH

eval 'exec "$OSRUBYBIN" -x -S $0 ${1+"$@"}'
echo "The 'exec \"$OSRUBYBIN\" -x -S ...' failed!" >&2
exit 1
#! This #!-line starts the real script, due to the marker: ruby
# -------+---------+---------+-------- + --------+---------+---------+---------+
p "Hello World"
exit 0


-- 
Garance Alistair Drosehn = drosihn / gmail.com
Senior Systems Programmer
Rensselaer Polytechnic Institute; Troy, NY; USA