The Accidental Rubyist

invalid byte sequence in UTF-8

Rewriting shell-scripts in ruby

leave a comment »

Just a note to myself (before I start some real work), that I’ve gotta rewrite some of my most used shell scripts in ruby, and write future ones in ruby. Reasons for frustration with bash scripting:

– if and loop syntax gets me
– unpredictable behavior of unix commands due to differences between gnu, macport and bsd versions. The options differ (take date for example, or split). The same program could pick up one egrep when running as a cronjob and another when executed by me on the prompt.
– regexp: one is no longer used to escaping + in a regexp as in “[0-9]\+”. Which reminds me that “\d” does not seem to work everywhere.
– File name and cat loops: data in loops gets split on spaces, have to go back and change delimiter to newlines.
– sensitivity to spaces
– updates to os x or macport often broken (one version of curl has stopped doing SSL due to some reason I forget — took ages to debug)

Writing these programs in ruby will help me learn faster. I could use highline for this work

Code comment:
// we are such morons. Wiz97 underwent a redesign between IE4 and IE5

# reverse order of lines (emulates ‘tac’) IMPROVE
$ cat | ruby -ne ‘BEGIN{}; @arr.push $_; END{puts @arr.reverse}’


Written by totalrecall

September 8, 2008 at 12:43 pm

Posted in ruby, unix

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: