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. I don't want to use cd to get to the script and I don't want invoke 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?
Yes, you can. Ruby should be installed on you Mac, lets say in /usr/bin/ruby
.
Script:
#!/usr/bin/ruby
puts 'Hello world'
Save script under some name, eh test.ruby. Execute:
chmod +x test.ruby
Add the directory your script is in to your PATH. Done!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.