如何在终端中执行 Ruby 脚本? [英] How to execute a Ruby script in Terminal?
本文介绍了如何在终端中执行 Ruby 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在 Mac 上设置了我需要的一切(Ruby、Rails、Homebrew、Git 等),我什至编写了一个小程序.现在,我如何在终端中执行它?我在 Redcar 中编写了程序并将其保存为 .rb,但我不知道如何通过终端执行它.我想运行该程序,看看它是否真的有效.我该怎么做呢?
I've set everything up that I need on my Mac (Ruby, Rails, Homebrew, Git, etc), and I've even written a small program. Now, how do I execute it in Terminal? I wrote the program in Redcar and saved it as a .rb, but I don't know how to execute it through Terminal. I want to run the program and see if it actually works. How do I do this?
推荐答案
只需调用:ruby your_program.rb
或
- 用
#!/usr/bin/env ruby
启动你的程序, - 通过运行
chmod +x your_program.rb
使您的文件可执行 - 然后做
./your_program.rb some_param
- start your program with
#!/usr/bin/env ruby
, - make your file executable by running
chmod +x your_program.rb
- and do
./your_program.rb some_param
这篇关于如何在终端中执行 Ruby 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文