Bash to ruby

Hi people,

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?

TIA

···

--
Fernando Cacciola
SciSoft
http://fcacciola.50webs.com

I do not know such a guide and a quick search does not seem to reveal much:

http://www.google.com/search?q="bash+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.

Having said that, there is at least
http://user-contributions.org/wikis/userwiki/index.php?title=Bash-to-Ruby

Kind regards

  robert

···

On 23.10.2007 18:35, Fernando Cacciola wrote:

Hi people,

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?

Fernando Cacciola wrote:

Hi people,

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?

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.

···

--
RMagick OS X Installer [http://rubyforge.org/projects/rmagick/\]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618\]
RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html\]

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.

···

On 01:35 Wed 24 Oct , Fernando Cacciola wrote:

Hi people,

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?

TIA

--
Fernando Cacciola
SciSoft
http://fcacciola.50webs.com

Interesting idea....

-Thufir

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...

The basic idea was:

$ruby -- rubyunix.rb 'fmt story.unformatted.txt > story.txt'

$ruby -- rubyunix.rb -f 'c:/path/to/unix/shell/script'

···

On 23.10.2007 18:35, Fernando Cacciola wrote:

So, is there any guideline on how to port bash scripts to ruby?

-------------------------------------------
Daniel Brumbaugh Keeney
Devi Web Development
Devi.WebMaster@gMail.com
-------------------------------------------

Well, I went ahead and setup a rubyforge project and mailing list available at

http://rubyforge.org/projects/rubyunix/
http://rubyforge.org/mailman/listinfo/rubyunix-developers

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.

···

-------------------------------------------
Daniel Brumbaugh Keeney
Devi Web Development
Devi.WebMaster@gMail.com
-------------------------------------------

one could extract some more speed out of it with a Ruby to C (ANSI C) converter....

the source would be in ruby, but the file would be in C :wink:

···

On Nov 13, 2007, at 3:45 PM, Thufir wrote:

Interesting idea....

Hello --

>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...

The basic idea was:

$ruby -- rubyunix.rb 'fmt story.unformatted.txt > story.txt'

$ruby -- rubyunix.rb -f 'c:/path/to/unix/shell/script'

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
(http://sourceforge.net/projects/ppt/\). A ruby counterpart to that
would be interesting. :slight_smile:

-- Thomas Adam

···

On 23/10/2007, Devi Web Development <devi.webmaster@gmail.com> wrote:

On 23.10.2007 18:35, Fernando Cacciola wrote:

So rewrite basic commands in Ruby? Sounds good. i'm in :smiley:

~ Ari
English is like a pseudo-random number generator - there are a bajillion rules to it, but nobody cares.

···

On Oct 23, 2007, at 2:56 PM, Devi Web Development wrote:

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...

The basic idea was:

$ruby -- rubyunix.rb 'fmt story.unformatted.txt > story.txt'

$ruby -- rubyunix.rb -f 'c:/path/to/unix/shell/script'

it'll never work

···

On Nov 13, 2007, at 18:51 , thefed wrote:

one could extract some more speed out of it with a Ruby to C (ANSI C) converter....

the source would be in ruby, but the file would be in C :wink:

"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...

#ifndef DIR_SEPARATOR_2
# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)

if eval test -z \"\${$var+set}\"; then
  relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=;
export $var; }; }; $relink_command"

must be fun to maintain this ;> )

···

--
Posted via http://www.ruby-forum.com/.

Marc Heiler wrote:

"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 :slight_smile:

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)

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...

#ifndef DIR_SEPARATOR_2
# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)

if eval test -z \"\${$var+set}\"; then
relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=;
export $var; }; }; $relink_command"

must be fun to maintain this ;> )

Fortuntely the scripts I need to port are not that overly-clever, so I don't unticipate much trouble.

Best

Fernandi