bash to ruby

F

Fernando Cacciola

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
 
R

Robert Klemme

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?

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
 
D

Devi Web Development

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'
 
T

Thomas Adam

Hello --

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

-- Thomas Adam
 
M

Marc Heiler

"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 ;> )
 
F

Fernando Cacciola

Marc said:
"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)
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
 
T

Tim Hunter

Fernando said:
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.
 
A

Ari Brown

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'

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


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

forgottenwizard

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

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

thefed

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 ;-)
 
R

Ryan Davis

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 ;-)

it'll never work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top