20 Apr 2012, 16:24
Leo-1_pragsmall

Leonel Santos (11 posts)

I added this shebang as the very first line of the file #!/usr/bin/env

I go to the directory where the rb file is located and then run todo.rb and get error “todo.rb: command not found”.

So I went directly to the /usr/bin directory. I found the env command and ran it. The output of the env command displays ruby paths and ruby data, like this…

MY_RUBY_HOME=/home/tallercreativo/.rvm/rubies/ruby-1.9.2-p290

PATH=/home/tallercreativo/.rvm/gems/ruby-1.9.2-p290/bin:/home/tallercreativo/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/tallercreativo/.rvm/rubies/ruby-1.9.2-p290/bin:/home/tallercreativo/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

GEM_PATH=/home/tallercreativo/.rvm/gems/ruby-1.9.2-p290:/home/tallercreativo/.rvm/gems/ruby-1.9.2-p290@global

RUBY_VERSION=ruby-1.9.2-p290

So since, I couldn’t make it work, I changed the shebang to point to ruby directly: #!/home/tallercreativo/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

and I get same command not found error.

What’s wrong?

20 Apr 2012, 18:10
Dmfcb_pragsmall

David Copeland (98 posts)

There’s two things at play.

1 - /usr/bin/env requires an argument to work, so your shebang line should read:

#!/usr/bin/env ruby

That tells @env@ to run the command @ruby@ from wherever it is in your environment path.

2 - your app must be in your path, so to run todo.rb from the current directory, you’d need to do

./todo.rb

(Note the @./@). Not sure how far along you are in the book, but if you have setup a project with the executable in the @bin@ directory, then you’d need to do

bin/todo.rb

Essentially, since your @PATH@ doesn’t contain the current directory or your project’s @bin@ directory, you need to explicitly include the path to the executable.

If all that sounds awful, it’s not a big deal when users install apps with RubyGems, since the executable gets installed into a location that is likely in the user’s path.

28 Oct 2012, 11:48
Generic-user-small

Weihong Guan (1 post)

I just began reading this book. It is quite inspiring. I believe it would be better if adding

chmod +x todo.rb

before excute it. For bash guys, this is quick basic, while for fleshmen, it is quite an issue.

  You must be logged in to comment