seq in Ruby

11:11PM Sep 11, 2006 in category Scriptlettes by David King

I was very saddened to find out how many systems don't ship with a seq command (or at least jot), which is a staple to any shell-scripting diet. So I added one to my shell scripting toolbox, here's a very basic version (it only supports the positive direction, and an incrementor of 1)

		#!/usr/bin/env ruby -w

		ARGV[0].to_i.upto(ARGV[1].to_i) { |i|
			puts i
		}
  

Now you can use a basic for-type loop, like this:

		#!/bin/sh

		for i in `seq 1 10`; do
			echo $i
		done
  

Comments:

Post a Comment:
Comments are closed for this entry.