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…

2007/8/23, Simon S. [email protected]:

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

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!

It’s not just arrays… lots of things are a pain…

2007/8/23, Daniel A. [email protected]:

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

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

On 8/23/07, M. Edward (Ed) Borasky [email protected] 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…

On 8/23/07, Robert K. [email protected] 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’d love to have some easier ruby type syntax for the
programming bits though…

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

2007/8/23, Daniel A. [email protected]:

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:

Kind regards

robert

On Aug 22, 2007, at 22:05, Simon S. 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?

require ‘shell’

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

On 23.08.2007 18:53, Daniel A. wrote:

On 8/23/07, Robert K. [email protected] 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…

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 Fri, 24 Aug 2007, Robert K. wrote:

2007/8/23, Daniel A. [email protected]:

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.
  • “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 Aug 23, 2007, at 3:01 PM, Tomas P.'s Mailing L. wrote:

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@:14(irb)

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

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

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

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!?

John J. 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”.

“Mogok” sounds pretty cool. “The Mogok Valley in north central Burma
is the source of the majority of the world’s finest rubies and
sapphires.”

hmm how could we fit a recursive acronym in there. MOGOK Overthrows
Gads Of Kakistrocracies?

On Aug 23, 2007, at 15:01, Tomas P.'s Mailing L. wrote:

On Fri, 24 Aug 2007, Robert K. wrote:

2007/8/23, Daniel A. [email protected]:

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.

Done!

require ‘shellwords’