Ruby shell?

what about a shell based on ruby? would such a thing be
useful/powerful? (aliasing Dir[/"usr/bin/*"] to ls returns an array,
can then specify ranges, etc) rash to
replace/include bash? :slight_smile: I'm pretty new to both linux and ruby, but
why or why not?

There is ruby based shells... Look them up and think about it some more...

You'd have to write a new shell with a ruby like syntax in all reality...

What about environment variables ?

You can't just start typing executable names that are in your path
you'd have to use back ticks or something for every single command you
want to run that isn't part of ruby...

etc...

ยทยทยท

On 8/23/07, Simon Schuster <significants@gmail.com> wrote:

what about a shell based on ruby? would such a thing be
useful/powerful? (aliasing Dir[/"usr/bin/*"] to ls returns an array,
can then specify ranges, etc) rash to
replace/include bash? :slight_smile: I'm pretty new to both linux and ruby, but
why or why not?

The topic comes up frequently here. You can search the archives for
more detail.
http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml

Oh, and btw, there *is* a Ruby shell: IRB. :slight_smile:

Kind regards

robert

ยทยทยท

2007/8/23, Simon Schuster <significants@gmail.com>:

what about a shell based on ruby? would such a thing be
useful/powerful? (aliasing Dir[/"usr/bin/*"] to ls returns an array,
can then specify ranges, etc) rash to
replace/include bash? :slight_smile: I'm pretty new to both linux and ruby, but
why or why not?

require 'shell'

(No, I don't know how to use it.)

ยทยทยท

On Aug 22, 2007, at 22:05, Simon Schuster wrote:

what about a shell based on ruby? would such a thing be
useful/powerful? (aliasing Dir[/"usr/bin/*"] to ls returns an array,
can then specify ranges, etc) rash to
replace/include bash? :slight_smile: I'm pretty new to both linux and ruby, but
why or why not?

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars

It would be cool if we could some how write a patch that would alter
bash arrays and all that stuff to make it more rubyish...

Bash is a mess!

ยทยทยท

On 8/23/07, Robert Klemme <shortcutter@googlemail.com> wrote:

2007/8/23, Simon Schuster <significants@gmail.com>:
> what about a shell based on ruby? would such a thing be
> useful/powerful? (aliasing Dir[/"usr/bin/*"] to ls returns an array,
> can then specify ranges, etc) rash to
> replace/include bash? :slight_smile: I'm pretty new to both linux and ruby, but
> why or why not?

The topic comes up frequently here. You can search the archives for
more detail.
http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml

Oh, and btw, there *is* a Ruby shell: IRB. :slight_smile:

Kind regards

robert

Daniel Aquino wrote:

There is ruby based shells... Look them up and think about it some more...

You'd have to write a new shell with a ruby like syntax in all reality...

What about environment variables ?

You can't just start typing executable names that are in your path
you'd have to use back ticks or something for every single command you
want to run that isn't part of ruby...

That was something that really irritated me when I migrated from "ksh"
to "ksh + (n)awk" and then to Perl. I just found actual *programming* in
"ksh" to be totally non-intuitive, and the pattern/action style of
"nawk" programming made more sense for what I was doing. Perl at least
was a real programming language. And of course Ruby is a lot more readable.

Interestingly enough the cases where I really needed arrays in bash
are extremely few. Do you need it frequently? If yes, what kind of
scripts / applications do you use it for?

Kind regards

robert

ยทยทยท

2007/8/23, Daniel Aquino <mr.danielaquino@gmail.com>:

It would be cool if we could some how write a patch that would alter
bash arrays and all that stuff to make it more rubyish...

Bash is a mess!

Yea I don't really use shell's for programming unless its something
simple or a system script...

How do you compare ksh to bash scripting ?

ยทยทยท

On 8/23/07, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:

I just found actual *programming* in "ksh" to be totally non-intuitive

--------

when it comes to shells... Bash is great for what it does..
It's completely based on what you need for moving around a unix system...
I'd love to have some easier ruby type syntax for the programming bits though...

It's not just arrays... lots of things are a pain..

ยทยทยท

On 8/23/07, Robert Klemme <shortcutter@googlemail.com> wrote:

2007/8/23, Daniel Aquino <mr.danielaquino@gmail.com>:
> It would be cool if we could some how write a patch that would alter
> bash arrays and all that stuff to make it more rubyish...
>
> Bash is a mess!

Interestingly enough the cases where I really needed arrays in bash
are extremely few. Do you need it frequently? If yes, what kind of
scripts / applications do you use it for?

Kind regards

robert

I tend to look at things very pragmatically - if you want to write something
that will run _anywhere_, write a sh script.
If you know all your target systems have a more terse language (such as Ruby
or Perl) installed, use that instead, as it's easier to maintain for simple
readability reasons. Systems that have bash installed very likely have Perl
installed.

Felix

ยทยทยท

-----Original Message-----
From: Daniel Aquino [mailto:mr.danielaquino@gmail.com]
Sent: Thursday, August 23, 2007 9:52 AM
To: ruby-talk ML
Subject: Re: ruby shell?

On 8/23/07, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:

> I just found actual *programming* in "ksh" to be totally
non-intuitive

Yea I don't really use shell's for programming unless its something
simple or a system script...

How do you compare ksh to bash scripting ?

--------

when it comes to shells... Bash is great for what it does..
It's completely based on what you need for moving around a
unix system...
I'd love to have some easier ruby type syntax for the
programming bits though...

Sorry, I find that too unspecific. Bash is great for what it's
intended to do. It's not a general purpose programming environment
but rather a scripting engine for day to day admin tasks. Maybe you
used the wrong hammer for your nail? :slight_smile:

Kind regards

robert

ยทยทยท

2007/8/23, Daniel Aquino <mr.danielaquino@gmail.com>:

It's not just arrays... lots of things are a pain..

I agree... but the programming side of it could becoming simpler...

ยทยทยท

On 8/23/07, Robert Klemme <shortcutter@googlemail.com> wrote:

It's not a general purpose programming environment
but rather a scripting engine for day to day admin tasks.

* Quoting in shell is hell.
* "A = 11" is a syntax error. WTF!
* "A=1; echo $A". Why once A and the other time $A? To make you weep?
* "ls 2>&1". Again: why is a filedescriptor once a number only and
   the other time has an ampersand in front? Such things give me nausea.
* for i in "all files that contain a star". How long do you have for that?
   30min? Less? More?
* arithmetics?!?!?!
* I could go on and on

Now why would a Ruby shell be wonderful? To reply to that, we need to know what's so nice about a shell:

* files are first class: "ls > /tmp/kak", how nice!
* pipes
* backticks: "cat `ls|grep *family*`"
* 0=true, !0=error_code
* fileglobs
* ...

How about being able to do these things with a Ruby DSL? Like:

   for lines in </etc/passwd> { line.split.map ... } > /tmp/passwd.changed
   h = Hash.new < `ls #{my_dir}`.special_sort | `tee /tmp/temp_copy`

That would be nice. The shell would need to be interactive and non-interactive...
*t

ยทยทยท

On Fri, 24 Aug 2007, Robert Klemme wrote:

2007/8/23, Daniel Aquino <mr.danielaquino@gmail.com>:

It's not just arrays... lots of things are a pain..

Sorry, I find that too unspecific. Bash is great for what it's
intended to do. It's not a general purpose programming environment
but rather a scripting engine for day to day admin tasks. Maybe you
used the wrong hammer for your nail? :slight_smile:

--
-----------------------------------------------------------
   Tomas Pospisek
   http://sourcepole.com - Linux & Open Source Solutions
-----------------------------------------------------------

If you only would disclose *where* exactly you see issues. It's easy to say "XYZ is bad" but the community (and probably you as well) would benefit more if you came up with concrete critizism.

Cheers

  robert

ยทยทยท

On 23.08.2007 18:53, Daniel Aquino wrote:

On 8/23/07, Robert Klemme <shortcutter@googlemail.com> wrote:

It's not a general purpose programming environment
but rather a scripting engine for day to day admin tasks.

I agree... but the programming side of it could becoming simpler...

I'm not a shell guru, but I'll take a crack at a few of those:

From: Tomas Pospisek's Mailing Lists [mailto:tpo2@sourcepole.ch]
Sent: Thursday, August 23, 2007 3:02 PM
To: ruby-talk ML
Subject: Re: ruby shell?

>> It's not just arrays... lots of things are a pain..
>
> Sorry, I find that too unspecific. Bash is great for what it's
> intended to do. It's not a general purpose programming environment
> but rather a scripting engine for day to day admin tasks. Maybe you
> used the wrong hammer for your nail? :slight_smile:

* Quoting in shell is hell.

Do you mean escaping characters? If so, sure, there's special characters in
double and single quoted strings that you need to learn. That's normal for
any "language".

* "A = 11" is a syntax error. WTF!

I'll give you that. I gather that the reason is ease of parsing, but it is
suboptimal.

* "A=1; echo $A". Why once A and the other time $A? To make you weep?

A $ sign starts interpolation. There's no interpoloation during variable
assignment.

* "ls 2>&1". Again: why is a filedescriptor once a number only and
   the other time has an ampersand in front? Such things give
me nausea.

An ampersand after > or < is the merging redirect operator, It doesn't
belong to the file descriptor.

* for i in "all files that contain a star". How long do you
have for that?
   30min? Less? More?

All you need to do is to escape the asterisk, which is a special character:

felix@felix-laptop:~$ touch test*test
felix@felix-laptop:~$ for file in *\**; do echo $file; done
test*test
felix@felix-laptop:~$

* arithmetics?!?!?!

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

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.

Humbly,

Felix

ยทยทยท

-----Original Message-----
On Fri, 24 Aug 2007, Robert Klemme wrote:
> 2007/8/23, Daniel Aquino <mr.danielaquino@gmail.com>:

How about being able to do these things with a Ruby DSL? Like:

  for lines in </etc/passwd> { line.split.map ... } > /tmp/passwd.changed
  h = Hash.new < `ls #{my_dir}`.special_sort | `tee /tmp/temp_copy`

That would be nice. The shell would need to be interactive and non-interactive...

I haven't looked at any of the projects already out there, just piqued my interest enough to generate this:

corey@leviathan ~> irb
>> class File
>> class << self
>> alias : new
>> end
>>
?> def lines &block
>> arr = self.readlines
>> arr.collect! {|line| yield line} if block_given?
>> arr
>> end
>> end
=> nil
>>
?> module Kernel
>> define_method :> do |file|
?> File.open(file, 'w') <<
?> case
?> when self.class.respond_to?(:join): self.join('\n')
>> else
?> self.to_s
>> end
>> end
>> end
=> #<Proc:0x014c146c@(irb):14>
>>
?>
?> File["/etc/passwd"].lines {|line| line =~ /^appserver/ ? nil : line }.compact > "/tmp/passwd.changed"
=> #<File:/tmp/passwd.changed>
>> quit
corey@leviathan ~> diff /etc/passwd /tmp/passwd.changed
27d26
< appserver:*:79:79:Application Server:/var/empty:/usr/bin/false

ยทยทยท

On Aug 23, 2007, at 3:01 PM, Tomas Pospisek's Mailing Lists wrote:

Done!

require 'shellwords'

ยทยทยท

On Aug 23, 2007, at 15:01, Tomas Pospisek's Mailing Lists wrote:

On Fri, 24 Aug 2007, Robert Klemme wrote:

2007/8/23, Daniel Aquino <mr.danielaquino@gmail.com>:

It's not just arrays... lots of things are a pain..

Sorry, I find that too unspecific. Bash is great for what it's
intended to do. It's not a general purpose programming environment
but rather a scripting engine for day to day admin tasks. Maybe you
used the wrong hammer for your nail? :slight_smile:

* Quoting in shell is hell.

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars

I think it is an excellent idea to have a Ruby shell!
Instead of Bash, call it Rash!
It wouldn't be easy to create the thing, considering the other *nix shells are all pretty robust and well developed.
However, they're also pretty old and do things in ways that are not always fun or easy. If you use bash or another shell all day every day, then you get used to it just like C++ or Java, but that doesn't make it better.

It's ambitious, but irb makes it seem like a darn good idea!

Imagine a new distro or two of linux: Rinux!!
An Ubuntu derivative called Rubuntu!!
with a shell named Rash!
How could you go wrong with cool names like that!?

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

ยทยทยท

From: Felix Windt [mailto:fwmailinglists@gmail.com]
#
# 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 .<digit> 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::PI*r; area=c*r; p area"
100
31415.9265358979
botp@botp-desktop:~$ ruby -e "r=100; c=Math::PI*r; area=c*r; 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

John Joyce wrote:

I think it is an excellent idea to have a Ruby shell!

Best shell I ever saw ran in the old DOS Foxbase. You enter commands in a little floating window (in character-mode, natch), and their "glass teletype" responses flowed in a big background window.

Someone should put that together with ncurses.

Instead of Bash, call it Rash!

Uy. I suppose it's too late for "Shellr".

ยทยทยท

--
  Phlip
  Test Driven Ajax (on Rails) [Book]
  "Test Driven Ajax (on Rails)"
  assert_xpath, assert_javascript, & assert_ajax