title: Ruby script: shebang with absolute path to ruby not working
body: <p>I am using Mac OS X. I have two versions (2.1.5 and 2.0.0) of Ruby installed. The former installed at /another/.path/to/ruby (there is a dot before "path" to mimic the fact that the path contains a dot-headed directory in between), in addition to the default system one (version 2.0.0) at /usr/bin/ruby. I used rbenv to install Ruby.</p>
  
  <p>After I manually set the PATH environment variable so the default ruby command will be found in another directory: /another/.path/to/ruby. Now I check </p>
  
  <pre><code>which -a ruby
  </code></pre>
  
  <p>It is using correct ruby first, as output. </p>
  
  <pre><code>/another/.path/to/ruby
  /usr/bin/ruby
  </code></pre>
  
  <p>Now I create a script, rbs, with the first line of shebang specifying the ruby to use.</p>
  
  <pre><code>#!/usr/bin/env ruby
  puts 'hey there'
  </code></pre>
  
  <p>Then I run</p>
  
  <pre><code>./rbs
  </code></pre>
  
  <p>it outputs 'hey there'. Good. Meanwhile, the Ruby is using the correct version.</p>
  
  <pre><code>/usr/bin/env ruby --version
  </code></pre>
  
  <p>as well as</p>
  
  <pre><code>ruby --version
  </code></pre>
  
  <p>both output 2.1.5. So it does great job to use the new version.</p>
  
  <p>However, here is where the problem occurs: now I update rbs file to be:</p>
  
  <pre><code>#!/another/.path/to/ruby
  puts 'hey there'
  </code></pre>
  
  <p>Note that I updated the shebang to use the absolute path to the desired ruby. then I run</p>
  
  <pre><code>./rbs
  </code></pre>
  
  <p>It outputs:</p>
  
  <pre><code>./rbs: line 2: puts: command not found
  </code></pre>
  
  <p>which is too weird;</p>
  
  <p>but if I run</p>
  
  <pre><code>ruby ./rbs
  </code></pre>
  
  <p>it outputs 'hey there' as normal. It looks like the shebang works perfect using /usr/bin/env ruby, but not for absolute path for the newly install ruby?</p>
  
  <p>Why is this? Is there a way to fix it so the updated script can still work by typing the following?</p>
  
  <pre><code>./rbs
  </code></pre>
  
  <p>Thanks!</p>