#!/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

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
#
#   This script just shows the most safe and reliable way to start a ruby
#   script, given that the executable for ruby can be in very different
#   directories on different platforms.  I have included plenty of tedious
#   comments for what is such a simple script.
#
#   It is possible that this works only for unix-y systems, since I do not
#   work on MS-Windows.  However, it is based on what the "Camel" book (from
#   O'Reilly) recommends as the safest way to write a perl scripts.  They
#   claim it works (for perl) across many platforms -- including MS-Windows.
#
#   To understand why this works, you'll want to read what '-x' means to
#   the ruby interpretter.  (ruby borrowed the ideas for '-x' from perl,
#   which came up with it to solve this very set of problems.  Python also
#   has a '-x' parameter, but I am not sure if it has the same meaning).
#
#   For some more background, see the thread
#	"proper usr/bin/env ruby shebang"
#	http://www.ruby-forum.com/topic/96121#199922
#
#   Before you tell me some obscure case where this strategy is not perfect,
#   let me assure you that I can find a problem with any simple strategy
#   that you would care to name.  One example of an unreliable solution is
#   "Use /usr/bin/env".  That simply is not reliable, especially if the
#   script needs to run on many platforms.  I have used this for the past
#   three or four years, on at least a half-dozen different Unix operating
#   systems, and it has always worked the way I needed it to work.
#
#   (For some OS's you may need to add more paths to the 'for...do' loop)
#
#			Garance Drosehn/gad@FreeBSD.org/Mar 12/2007

puts "Using #{ENV['OSRUBYBIN']}:  Hello world!"
