From: Stu Date: 2013-01-02T08:30:25+09:00 Subject: Re: using shebang with rvm? It's primarily for portability. Using env more or less defeats portability issues as every box could have ruby installed somewhere else. For example rvm really is just a environment hack. When you call a program, in this case ruby, with env your shell will locate the first ruby it finds in the path. This is just a hashed lookup table for speed. Basically when you call for example % ruby program.rb it expands to (say on my system) % /usr/local/bin/ruby /path/to/my/program.rb -- of course rvm takes precedence over the system paths as that's what the utility was designed to do. A common mistake, which your observing, is where a direct path is used; the programmer does not take into account that different operating systems put their binaries in different directories. Always use env. Any of the absolute paths which you see are usually from uninformed dilettantes or users whom want world domination for their tools or OSes and are throwing a fit by forcing any of their users to write a small sed script to patch their install. If you would like to see your paths hash you can simply type in the command hash at the prompt. If you need to update your hash you can use the -r option. If you would like to know more, outside of the web wiki, read the ash (not bash) man page: http://man.freebsd.org/sh Quote: hash [-rv] [command ...] The shell maintains a hash table which remembers the locations of commands. With no arguments whatsoever, the hash command prints out the contents of this table. Entries which have not been looked at since the last cd command are marked with an asterisk; it is possible for these entries to be invalid. With arguments, the hash command removes each specified command from the hash table (unless they are functions) and then locates it. With the -v option, hash prints the locations of the com- mands as it finds them. The -r option causes the hash command to delete all the entries in the hash table except for functions. ~Stu On Thu, Dec 27, 2012 at 12:23 AM, Wesley Rishel wrote: > Thanks, but most shebang files I have seen include an absolute path to > the language interpreter. Rvm does not intervene when the shell is > interpreting a script containing a shebang. So, for example, if you > create this script on OS 10.8 it returns 1.8.7 no matter what version > you have selected in rvm. > > $ cat tryshbang.rb > #! /usr/bin/ruby > puts RUBY_VERSION > $ ./tryshbang.rb > 1.8.7 > $ > > I have since found the following recommendation in the Wikipedia article > on shebang: http://en.wikipedia.org/wiki/Shebang_(Unix) > > #! /usr/bin/env ruby > puts RUBY_VERSION > > It works. > > -- > Posted via http://www.ruby-forum.com/. >