From: Sam Duncan Date: 2012-04-25T14:13:42+09:00 Subject: Re: -BEGINNERS- Where do I Start? On 25/04/12 16:46, Thought M. wrote: > update- > > I got the irb to work in my terminal and it is functioning just as I'd > hoped. > > Now I just am curious about the hash bang. > > The CHMOD is change modify i assume and the u+x is making it "x" > executable, path is to define which file to make changes to and > modify.... yeah > > So the CHMOD, is that to finalize the ruby code, as in, can i add an > make changes to the code still? Making the file executable doesn't lock > the code right, just makes it turn from writting to functionable > material right? > > So can you explain what the "!" path/to/env Ruby is all about? > > > THANKS- > This should get you started with hashbang lines: http://en.wikipedia.org/wiki/Shebang_(Unix) I'll try to illustrate with a few examples. Assume a script called 'rubyduby.rb' in your current working directory, and that '>' represents your shell prompt. Lets say rubyduby.rb looks like this; ----------------------------------------------- require 'etc' puts "RubyDuby: #{Etc.getlogin}" ----------------------------------------------- # choose your ruby with rvm, and run your script > rvm use 1.9.3 > ruby ./rubyduby.rb Now this will 'feed' your script to the first ruby interpreter your shell finds in your path. If you had another ruby installed with rvm, you could switch to that and run it again. # choose another ruby with rvm, and run your script > rvm use rbx > ruby ./rubyduby.rb But what about if I am tired and don't want to keep typing ruby? I need to give my script a hashbang, and make it executable. Now rubyduby.rb looks like this; ----------------------------------------------- #!/usr/bin/env ruby require 'etc' puts "RubyDuby: #{Etc.getlogin}" ----------------------------------------------- # After adding a hashbang line, make it executable, and run it! > chmod u+x ./rubyduby.rb > ./rubyduby.rb To answer a few questions; *) Will making the file executable 'lock' or 'compile' my file in some way? No; and you can continue to run it by typing ruby first if you like. *) Can I edit my newly executable script? Yes; save and rerun to your hearts content. *) Why make the hashbang line with env instead of ruby directly? Because if you point it directly at ruby (/usr/bin/ruby or something), then switching rubies with rvm won't switch the ruby your script is invoked with. Wrapping it with env causes it to be run with the ruby you chose with rvm (generally!). 'man env' for more info. Hope that helps =] Sam