I’m not a ruby developer just yet, but I’ve been reading a couple of
in-depth references and I already like it… a lot.
Today I got, once again as usual, annoyed by having to get into cygwin just to run build-related bash scripts from within windows. But I must
be developing some ruby cells in my blood already since I thought:
that’s
it… I’m rewritting them in ruby!
So, is there any guideline on how to port bash scripts to ruby?
I guess this happens rarely if ever - Unix like operating systems
nowadays heavily depend on (ba)sh scripting and I doubt anyone is
changing that (although the topic comes up from time to time).
Both are significant different so that an automated conversion would
likely yield ugly Ruby code that you could rewrite faster and shorter.
So, is there any guideline on how to port bash scripts to ruby?
A while back I considered writing some of the unix commands (and
perhaps basic shell scripting) in cross-platform ruby, but decided it
wasn’t especially useful. Are people interested in that? Would anyone
be willing to help. I’m kind of busy right now, but if there’s
demand…
It’s an interesting idea, and one that I would be willing to help
with, providing it was outlined a bit more. I’m quite busy with the
Ruby Mentors project, but that’s peacemeal. Don’t forget that this
idea isn’t unique; there’s already a Perl Power Tools
(Perl Power Tools download | SourceForge.net). A ruby counterpart to that
would be interesting.
“So, is there any guideline on how to port bash scripts to ruby?”
Well the basic functionality of mkdir or cd is all there in std ruby.
Do you have a specific problem? Just post away here, I am sure people
like to squish away with the ugliness of shell scripts (did you guys
know that libtool has
~7500 lines of shell code? … it has some genious macros…
So, is there any guideline on how to port bash scripts to ruby?
You might find it useful to look at Ruby’s un.rb library. It implements
a lot of common *ix commands (cd, rm, cp, mkdir, etc.) using FileUtils.
It might give you some ideas.
“So, is there any guideline on how to port bash scripts to ruby?”
Well the basic functionality of mkdir or cd is all there in std ruby.
Do you have a specific problem? ´
Not yet, because I haven’t started
But I’ll follow your advice and post on demand…
As I said I don’t really know ruby. I read quite a lot already but
haven’t
got my hands dirty yet with some real stuff, so I’m using this as an
excuse
so do something real.
Last time I found motivation in programming something arbitrary just to
learn a new language was about 20 years ago, but this would be
inmediately
useful, so should be fun.
I’ll try to identify patterns and post here my proposed counterparts.
For instance, I gather so far that FileUtils would provide most file/dir
handling.
My probably next step is to find out how to port typical grep/sed
commands
(their typical usage, not all of it)
So, is there any guideline on how to port bash scripts to ruby?
Having done this a time or two (with my own scripts, nothing major),
what you need to do is map out what the script does/write out a spec so
that you know what needs to be done in what way, then you need to start
scripting. I’d keep the same basic structure to it for the first
revision, then go back later to refactor it.
The only problem will be with some *nix commands that you may have a
problem replacing (sed and grep are two examples, but if you can replace
sed, you’ve replaced grep pretty much).
An idea on what all it requires might help if you want some help.
I found un.rb by WATANABE Hirofumi and rbsh by Antonio Salazar, but if
anyone knows another resource, let me know. Hopefully, further
discussions will take place on the rubyunix-developers mailing list.