[英]Installing and running a ruby script in the terminal in OSX Lion
I have a ruby script that I will use quite often, so I would like to be able to run it directly from the terminal, ie just open the terminal and type the name of the script like I would with ls, chmod or any other default command. 我有一个经常使用的ruby脚本,因此我希望能够直接在终端上运行它,即打开终端并像使用ls,chmod或其他任何默认值一样键入脚本的名称命令。 I don't want to use cd to get to the script and I don't want invoke Ruby.
我不想使用cd来获取脚本,也不想调用Ruby。 I would simply like to type the name of the script with its argument and get the result.
我只想输入脚本名称及其参数并获取结果。
Is it possible? 可能吗? If yes, where do I put the script?
如果是,我应该将脚本放在哪里? How do I tell OSX that it should treat it as one of its own default commands?
我如何告诉OSX应该将其视为自己的默认命令之一?
Yes, you can. 是的你可以。 Ruby should be installed on you Mac, lets say in
/usr/bin/ruby
. Ruby应该安装在Mac上,例如
/usr/bin/ruby
。
Script: 脚本:
#!/usr/bin/ruby
puts 'Hello world'
Save script under some name, eh test.ruby. 用一些名称保存脚本,例如test.ruby。 Execute:
执行:
chmod +x test.ruby
Add the directory your script is in to your PATH. 将脚本所在的目录添加到PATH。 Done!
做完了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.