问题描述
我正在使用 Ubuntu.我正在尝试运行一个 ruby 文件 todo.rb我将此shebang添加为文件的第一行
I'm using Ubuntu. I'm trying to run a ruby file todo.rbI added this shebang as the very first line of the file
#!/usr/bin/env ruby
我转到rb文件所在的目录,然后运行todo.rb并得到错误todo.rb: command not found
.
I go to the directory where the rb file is located and then run todo.rb and get error todo.rb: command not found
.
所以我直接进入了/usr/bin目录.我找到了 env 命令并运行了它.env
命令的输出显示 ruby 路径和 ruby 数据:
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:
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
因此,我无法使其工作,我将shebang更改为直接指向ruby:
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?
推荐答案
您需要首先使您的脚本可执行:
You need to first make your script executable:
chmod +x todo.rb
那么你需要像这样运行它:
then you need to run it like so:
./todo.rb
你不能只说 todo.rb
来运行它,除非你把它放在你的 PATH
中,在这种情况下,你可以从任何地方这样做.
You cannot run it by just saying todo.rb
, unless you place it in your PATH
, in which case you can do so from anywhere.
这篇关于Ruby 1.9 如果我有一个指向 ruby 的shebang,为什么系统看不到它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!