On Fri, 2 Feb 2007, Garance A Drosehn wrote:

> #!/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
>
> 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
> ....[ and then the first line of the real ruby script]...
>
> Obviously you could add the '-w' after '-x' on the eval/exec line, if you
> also wanted that option.  And if you do something weird like install
> 'ruby' in /bin (so that you can find out when /usr is not mounted), then
> you'd need to add that to the list of directories which are searched.
>
> In some cases, I also set a new value for PATH= in the /bin/sh
> portion of the script, to avoid ruby's warning about an "Insecure
> world writable dir".  That warning message can also be avoided
> by setting $VERBOSE in the ruby script, but in some cases it's
> just easier for me to change the value for PATH.
>
> I suspect that all this is too esoteric for most people to other with!  :-)
> It really is rather absurdly complicated to get 100% right in 100% of
> the situations that every ruby script might be run in.

thanks garance!  i'm filing this under 'definitive' in my mail ;-)

-a
-- 
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama