Ruby: building a command-line application

Some great tips on building a command line application in Ruby:

1. Add a shebang line to your script

Rather than hard-coding the path to the Ruby executable in your script, use env to figure it out from your environment. E.g.

#!/usr/bin/env ruby

This makes your script easier to move between servers where the Ruby binary may be in different locations.

2. Make your script executable

chmod +x path/to/your/script

3. Add the path to your lookup path so that it can be called directly

export PATH=/Users/seacreature/devel/rcat/bin:$PATH

On a Mac you’d do this in your bash_profile.

Leave a Reply

Your email address will not be published. Required fields are marked *