Ruby shell?

From: Felix W. [mailto:[email protected]]

felix@felix-laptop:~$ expr 20 + 5 - 4

21

Now, I work in the shell all day long, so maybe I’m just used to those

things, but I didn’t find them any harder to learn than some

of the ground rules for Ruby.

for shell gurus, it probably should not matter. But w the current IT
state, of admins beset with multitude of problems amongst a sea of
heteregeneous platforms, architecture, networks, os, applications,
languages, whatever, we need a tool that is general purpose, kind on our
brains, yet powerful to drive a small script up to the the biggest web
framework imagineable.

eg,

botp@botp-desktop:~$ expr 1+1
1+1
botp@botp-desktop:~$ expr 1+.5
1+.5
botp@botp-desktop:~$ expr 1+0.5
1+0.5

ruby on the other hand is kinder,…

botp@botp-desktop:~$ ruby -e “p 1+1”
2
botp@botp-desktop:~$ ruby -e “p 1+.5”
-e:1: no . floating literal anymore; put 0 before dot
p 1+.5
^
-e:1: syntax error, unexpected ‘.’
p 1+.5
^
i see. so ruby is kind to the programmer, providing much error info as
possible

botp@botp-desktop:~$ ruby -e “p 1+0.5”
1.5
botp@botp-desktop:~$ ruby -e “p 1+0.5+Math::PI”
4.64159265358979
botp@botp-desktop:~$ ruby -e “p r=100; c=Math::PIr; area=cr; p area”
100
31415.9265358979
botp@botp-desktop:~$ ruby -e “r=100; c=Math::PIr; area=cr; p area”
31415.9265358979
botp@botp-desktop:~$ ruby -e “p 2**999”
535754303593133660474212524530000905280702405852766803721875194185175525
562468061246599189407847929063797336458776573412593572642846157021799228
878734928740196728388741211549271053730253118557093897709107652323749179
097063369938377958277197303853145728559823884327108383021491582631219341
8602834034688

botp@botp-desktop:~$ echo hello, world | ruby -e “p
gets.chomp.capitalize”
“Hello, world”

botp@botp-desktop:~$ rails -v

ruby is kind to me, …or maybe, i’m just getting old and lazy :frowning:

kind regards -botp

"Now why would a Ruby shell be wonderful? "

Aside and above all the niceties of Ruby, its really
about objects and messages - in a shell. A shell on top
of an operating system… or at least its first
citizen. :slight_smile:

Where you can think of your whole operating system as
interacting objects doing nice little stuff (without
being restricted to the old unix philosophy of using
tiny non-GUI thingies with odd names to achieve certain
tasks…)

“Imagine a new distro or two of linux: Rinux!!”

I think ultimately, a distro is nothing without
people backing it up. I think this is a little too ambitious,
as far as I know the only really ambitious project
on that (RubyX, later renamed to Heretix) disbanded because
the two main devs no longer had the time (and I also
suspect a little bit, they felt slightly burnt out. But
that is my opinion.)

A shell would be much more of a mundane task :wink:

“I tend to look at things very pragmatically - if you want to write
something that will run anywhere, write a sh script.”

I think being pragmatic is very good. Personally though,
I feel sh style is not only old and ugly - it is a lot
more limited than ruby. I havent seen DSLs usage or GUI
handling in shell scripts, new ideas seem to neither spread
into shell and its “legacy” so to me its a pretty dead
concept - I always have ruby ready, and even if i carry
it around on an USB stick … :slight_smile:

But sure, shell scripts may have several use cases, even
perl hasn’t killed off shell scripts! (But then again
Perl also has no maintained perl shell afaik) :wink:

Simon S. wrote:

I think it is an excellent idea to have a Ruby shell!
Phlip
http://www.oreilly.com/catalog/9780596510657/
“Test Driven Ajax (on Rails)”
assert_xpath, assert_javascript, & assert_ajax

Its never too late for Web2.0-esque names.

Marc H. wrote:

Where you can think of your whole operating system as
interacting objects doing nice little stuff (without
being restricted to the old unix philosophy of using
tiny non-GUI thingies with odd names to achieve certain
tasks…)

Text is a universal format unless you are a computer.

“Imagine a new distro or two of linux: Rinux!!”

Oh please… not another one !!!

A shell would be much more of a mundane task :wink:

I once tried to write a shell in Ruby as a toy project in my
~/Programming/Ruby directory but got bored…

If it had not all ready been largely done in C, Perl, Lisp, and
KornShell
versions I’d probably work on a shell and posix oriented userland for
fun.

concept - I always have ruby ready, and even if i carry
it around on an USB stick … :slight_smile:

The scripts i write are bourne shell scripts, so they should generally
work
on almost any system with a compliant shell as long as all of the used
programs are installed. I never write BASH scripts or use GNU
extensions…

The point is it’s a shell for interacting with the computer! It just
happens
to be scriptable, which can be used to create very useful tools. It’s
not
really meant to be a full programming language so much as it is there to
enable you to build useful utilities without being a Master Coder.

The Bourne Again and Korn Shells add a lot of things to shell scripting,
Many
Unix utilities have been rewritten as Korn Shell scripts and it even can
be
made to provide some interfaces for GUI work. ksh93 may as well be a
complete
programming language unlike POSIX Compatible Bourne shell scripts

But sure, shell scripts may have several use cases, even
perl hasn’t killed off shell scripts! (But then again
Perl also has no maintained perl shell afaik) :wink:

Personally I think perl scripts are better then sh but there are some
applications on most Unix systems that are to good not to reuse for some
tasks. If you need to script the operating system, I would say go for
the
highest level of shell script you can (e.g. ksh93, ksh88, bourne, bash
or
powershell, cmd, command e.t.c.). If your wanting to port it between OS
families, time for a true and complete programming language meant for
Programming.

Perl is present on almost any Unix like system these days, *BSD and
Linux/GNU
systems generally include them in the base, Mac OS X might I don’t know:
Windows is the last bastard not in the heap !!! So it would be a good
choice
as fewer systems would require it installed.

I think the Perl Shells (psh) last release was 21 Jul 2007 on CPAN. I’m
a zsh
man but I used to collect different shells, languages, terminal
emulators,
window managers, and text editors :slight_smile:

I’m very tempted to install Ruby on my server because I enjoy working in
Ruby.
The only problem is when the Public Domain ksh and Perl pre-installed
it’s
hard to warrant it. And my administration-side tasks don’t really
require a
new tool, even if it would be my favorite :’(

TerryP.

On Wed, Aug 29, 2007 at 08:17:36AM +0900, Terry P. wrote:

Marc H. wrote:

A shell would be much more of a mundane task :wink:

I once tried to write a shell in Ruby as a toy project in my
~/Programming/Ruby directory but got bored…

If it had not all ready been largely done in C, Perl, Lisp, and KornShell
versions I’d probably work on a shell and posix oriented userland for fun.

I wonder why irb isn’t good enough. Why not use that, if you need a
Ruby
shell? Using chpass on FreeBSD to set a shell to irb[1] (for instance)
works just fine and, while I haven’t tried it, I’m sure you can set a
user’s default shell to irb on Linux just as easily.

My experience with irb and psh is that psh is a much more annoying shell
than irb. In fact, if I didn’t prefer working in the standard shell for
any given Unix or Unix-like OS, I’d probably be using either irb or
(maybe) esh as my shell a lot of the time.

Okay, now that I’ve thought about it, maybe irb isn’t ideal – if only
because stuff like executing ls would require something like the
following:

puts ls

. . . or:

system ‘ls’

That could get annoying after a while. Okay, ignore what I said – if
you want a Ruby shell, I guess you need one other than irb. Now that I
think about it, esh has some annoyances with the parentheses
requirements for all native commands, too.

Damn. I’m not sure there was really a point to this email at all, now.
I’ll go ahead and spam the list with it anyway, though, since I went to
all the trouble of typing it.

[1]: . . . assuming, of course, you have the path to irb specified in
the
/etc/shells file.

Chad P. wrote:

That could get annoying after a while.
That could be worked around quite easily with method_missing. Then you’d
only
need system or `` to invoke programs that are named the same as ruby
methods.
What I’d consider more of a problem is tab-completion. It would be
possible to
make irb’s tab-completion complete program names too by simply defining
a
method for every executable in the PATH, but I don’t see a way to make
it
complete filenames or other kind of parameters to the programs
(especially
since those’d have to be quoted).