Ruby 1.9 如果我有一个指向 ruby​​ 的shebang,为什么系统看不到它? [英] Ruby 1.9 If I have a shebang pointing to ruby, why doesn't the system see it?

查看:39
本文介绍了Ruby 1.9 如果我有一个指向 ruby​​ 的shebang,为什么系统看不到它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Ubuntu.我正在尝试运行一个 ruby​​ 文件 todo.rb我将此shebang添加为文件的第一行

I'm using Ubuntu. I'm trying to run a ruby file todo.rb I 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,为什么系统看不到它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆