[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Sigh! I'm depressed. Debian vs Ruby and the backtick and subshells

John Carter

8/12/2008 5:49:00 AM

I have just strace'd weird bug to it's root cause.

For decades bash was the "sh" of choice for linux systems.

Then somebody threw some money at the Debian foundation to make Debian
boot faster.

The solution was to tweak the init scripts to be perfectly POSIX
Lowest Common Denominator "sh" compatible, and then make dash the
default "sh".

To allow for legacy scripts that expect /bin/sh === /bin/bash you can
sudo dpkg-reconfigure dash
and switch back to sh === bash

Thus on Debian (and Debian derivatives like Ubuntu) Rubies backtick
(iff there is a glob or a redirection present) is HARDCODED to /bin/sh
but will (depending on the users whim) give you dash or bash.

For example the &> redirection is a bashism...
ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2008-08-12 16:54 /bin/sh -> dash
build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls NOFILEWITHTHISNAME&>foo")'
ls: cannot access NOFILEWITHTHISNAME: No such file or directory
build@ws1419:~/AutomatedBuild/test$ cat foo
build@ws1419:~/AutomatedBuild/test$ sudo dpkg-reconfigure dash
Removing `diversion of /bin/sh to /bin/sh.distrib by dash'
Removing `diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash'
build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls NOFILEWITHTHISNAME&>foo")'
build@ws1419:~/AutomatedBuild/test$ cat foo
ls: cannot access NOFILEWITHTHISNAME: No such file or directory

AAARGH!

As I always say... if a bug is hard to find... you won't know what to
do with it once you find it.



John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand


18 Answers

Robert Klemme

8/12/2008 6:35:00 AM

0

On 12.08.2008 07:48, John Carter wrote:
> I have just strace'd weird bug to it's root cause.
>
> For decades bash was the "sh" of choice for linux systems.
>
> Then somebody threw some money at the Debian foundation to make Debian
> boot faster.
>
> The solution was to tweak the init scripts to be perfectly POSIX
> Lowest Common Denominator "sh" compatible, and then make dash the
> default "sh".
>
> To allow for legacy scripts that expect /bin/sh === /bin/bash you can
> sudo dpkg-reconfigure dash
> and switch back to sh === bash
>
> Thus on Debian (and Debian derivatives like Ubuntu) Rubies backtick
> (iff there is a glob or a redirection present) is HARDCODED to /bin/sh
> but will (depending on the users whim) give you dash or bash.
>
> For example the &> redirection is a bashism...
> ls -l /bin/sh
> lrwxrwxrwx 1 root root 4 2008-08-12 16:54 /bin/sh -> dash
> build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls NOFILEWITHTHISNAME&>foo")'
> ls: cannot access NOFILEWITHTHISNAME: No such file or directory
> build@ws1419:~/AutomatedBuild/test$ cat foo
> build@ws1419:~/AutomatedBuild/test$ sudo dpkg-reconfigure dash
> Removing `diversion of /bin/sh to /bin/sh.distrib by dash'
> Removing `diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash'
> build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls NOFILEWITHTHISNAME&>foo")'
> build@ws1419:~/AutomatedBuild/test$ cat foo
> ls: cannot access NOFILEWITHTHISNAME: No such file or directory
>
> AAARGH!
>
> As I always say... if a bug is hard to find... you won't know what to
> do with it once you find it.

You should probably mention that the bug is actually in _your_ code: if
you rely on bash features present in /bin/sh then that's the error.

:-)

Kind regards

robert

Magicloud Magiclouds

8/12/2008 6:50:00 AM

0

I am using Debian sid, which sh is bash.
And, in fact, I hate ruby's way of system call. Ugly and hard to use and
stupid hardcoded.

John Carter wrote:
> I have just strace'd weird bug to it's root cause.
>
> For decades bash was the "sh" of choice for linux systems.
>
> Then somebody threw some money at the Debian foundation to make Debian
> boot faster.
>
> The solution was to tweak the init scripts to be perfectly POSIX
> Lowest Common Denominator "sh" compatible, and then make dash the
> default "sh".
>
> To allow for legacy scripts that expect /bin/sh === /bin/bash you can
> sudo dpkg-reconfigure dash
> and switch back to sh === bash
>
> Thus on Debian (and Debian derivatives like Ubuntu) Rubies backtick
> (iff there is a glob or a redirection present) is HARDCODED to /bin/sh
> but will (depending on the users whim) give you dash or bash.
>
> For example the &> redirection is a bashism...
> ls -l /bin/sh
> lrwxrwxrwx 1 root root 4 2008-08-12 16:54 /bin/sh -> dash
> build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls
> NOFILEWITHTHISNAME&>foo")'
> ls: cannot access NOFILEWITHTHISNAME: No such file or directory
> build@ws1419:~/AutomatedBuild/test$ cat foo
> build@ws1419:~/AutomatedBuild/test$ sudo dpkg-reconfigure dash
> Removing `diversion of /bin/sh to /bin/sh.distrib by dash'
> Removing `diversion of /usr/share/man/man1/sh.1.gz to
> /usr/share/man/man1/sh.distrib.1.gz by dash'
> build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls
> NOFILEWITHTHISNAME&>foo")'
> build@ws1419:~/AutomatedBuild/test$ cat foo
> ls: cannot access NOFILEWITHTHISNAME: No such file or directory
>
> AAARGH!
>
> As I always say... if a bug is hard to find... you won't know what to
> do with it once you find it.
>
>
>
> John Carter Phone : (64)(3) 358 6639
> Tait Electronics Fax : (64)(3) 359 4632
> PO Box 1645 Christchurch Email : john.carter@tait.co.nz
> New Zealand
>
>
>


Robert Klemme

8/12/2008 7:07:00 AM

0

On 12 Aug., 08:49, Magicloud Magiclouds
<magicloud.magiclo...@gmail.com> wrote:
> I am using Debian sid, which sh is bash.
> And, in fact, I hate ruby's way of system call. Ugly and hard to use and
> stupid hardcoded.

/bin/sh is the least common denominator for all Unix like systems. So
in terms of portability it is a good choice to make this the default
shell. And if you do not like that shell, you can use another one
anytime:

09:06:03 ~$ ruby -e 'system "/bin/bash", "-c", "echo \"$
{BASH_VERSINFO[*]}\""'
3 2 39 19 release i686-pc-cygwin
09:06:06 ~$ ruby -e 'system ENV["SHELL"], "-c", "echo \"$
{BASH_VERSINFO[*]}\""'
3 2 39 19 release i686-pc-cygwin
09:06:07 ~$

Put that into a method and you can use your bash whenever you want.
No need to blame Ruby here when in fact it behaves reasonable.

Kind regards

robert

F. Senault

8/12/2008 9:58:00 AM

0

Le 12 août 2008 à 09:07, Robert Klemme a écrit :

> Put that into a method and you can use your bash whenever you want.
> No need to blame Ruby here when in fact it behaves reasonable.

Not that you can overload the method, too...

module Kernel
def `(v)
...
end
end

(Maybe it's a bit eeeeevil...)

Fred
--
She rules until the end of time
She gives and she takes
She rules until the end of time
She goes her own way (Within Temptation, Mother Earth)

Phlip

8/12/2008 11:35:00 AM

0

>> build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls
>> NOFILEWITHTHISNAME&>foo")'

Magicloud Magiclouds wrote:

> I am using Debian sid, which sh is bash.
> And, in fact, I hate ruby's way of system call. Ugly and hard to use and
> stupid hardcoded.

The choice of `` is deliberate. It's to inspire you to get off your lazy butt
and learn the Ruby-internal way to do something, such as Pathname.glob. There's
always a way to avoid a shell command...

--
Phlip

Michael Guterl

8/12/2008 11:53:00 AM

0

On Tue, Aug 12, 2008 at 7:37 AM, Phlip <phlip2005@gmail.com> wrote:
>>> build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls
>>> NOFILEWITHTHISNAME&>foo")'
>
> Magicloud Magiclouds wrote:
>
>> I am using Debian sid, which sh is bash.
>> And, in fact, I hate ruby's way of system call. Ugly and hard to use and
>> stupid hardcoded.
>
> The choice of `` is deliberate. It's to inspire you to get off your lazy
> butt and learn the Ruby-internal way to do something, such as Pathname.glob.
> There's always a way to avoid a shell command...
>
This is a ridiculous claim. I'd spend more time writing a response,
but I'm hoping you're just being sarcastic.

Michael Guterl

M. Edward (Ed) Borasky

8/12/2008 12:55:00 PM

0

On Tue, 2008-08-12 at 14:48 +0900, John Carter wrote:
> I have just strace'd weird bug to it's root cause.
>
> For decades bash was the "sh" of choice for linux systems.
>
> Then somebody threw some money at the Debian foundation to make Debian
> boot faster.
>
> The solution was to tweak the init scripts to be perfectly POSIX
> Lowest Common Denominator "sh" compatible, and then make dash the
> default "sh".
>
> To allow for legacy scripts that expect /bin/sh === /bin/bash you can
> sudo dpkg-reconfigure dash
> and switch back to sh === bash
>
> Thus on Debian (and Debian derivatives like Ubuntu) Rubies backtick
> (iff there is a glob or a redirection present) is HARDCODED to /bin/sh
> but will (depending on the users whim) give you dash or bash.
>
> For example the &> redirection is a bashism...
> ls -l /bin/sh
> lrwxrwxrwx 1 root root 4 2008-08-12 16:54 /bin/sh -> dash
> build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls NOFILEWITHTHISNAME&>foo")'
> ls: cannot access NOFILEWITHTHISNAME: No such file or directory
> build@ws1419:~/AutomatedBuild/test$ cat foo
> build@ws1419:~/AutomatedBuild/test$ sudo dpkg-reconfigure dash
> Removing `diversion of /bin/sh to /bin/sh.distrib by dash'
> Removing `diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash'
> build@ws1419:~/AutomatedBuild/test$ ruby -e 'system("ls NOFILEWITHTHISNAME&>foo")'
> build@ws1419:~/AutomatedBuild/test$ cat foo
> ls: cannot access NOFILEWITHTHISNAME: No such file or directory
>
> AAARGH!
>
> As I always say... if a bug is hard to find... you won't know what to
> do with it once you find it.

Why does Debian use dash? I've never even *heard* of dash until I saw
this thread! Is there some religious war against bash?
--
M. Edward (Ed) Borasky
ruby-perspectives.blogspot.com

"A mathematician is a machine for turning coffee into theorems." --
Alfréd Rényi via Paul ErdÅ?s


brabuhr

8/12/2008 1:07:00 PM

0

On Tue, Aug 12, 2008 at 8:54 AM, M. Edward (Ed) Borasky
<znmeb@cesmail.net> wrote:
> On Tue, 2008-08-12 at 14:48 +0900, John Carter wrote:
>> Then somebody threw some money at the Debian foundation to make Debian
>> boot faster.
>
> Why does Debian use dash? I've never even *heard* of dash until I saw
> this thread! Is there some religious war against bash?

http://en.wikipedia.org/wiki/Debian_Almq...
"Dash, like ash, executes scripts faster than bash and depends on
fewer libraries. It is believed to be more reliable in case of upgrade
problems or disk failures."

https://wiki.ubuntu.com/D...
"The major reason to switch the default shell was efficiency. bash is
an excellent full-featured shell appropriate for interactive use;
indeed, it is still the default login shell. However, it is rather
large and slow to start up and operate by comparison with dash. A
large number of shell instances are started as part of the Ubuntu boot
process. Rather than change each of them individually to run
explicitly under /bin/dash, a change which would require significant
ongoing maintenance and which would be liable to regress if not paid
close attention, the Ubuntu core development team felt that it was
best simply to change the default shell."

Avdi Grimm

8/12/2008 2:26:00 PM

0

On Tue, Aug 12, 2008 at 1:48 AM, John Carter <john.carter@tait.co.nz> wrote:
> Thus on Debian (and Debian derivatives like Ubuntu) Rubies backtick
> (iff there is a glob or a redirection present) is HARDCODED to /bin/sh
> but will (depending on the users whim) give you dash or bash.

For as long as I've been working with *nix systems the rule was
always: either *explicitly* invoke Bash, or understand and use only
the lowest common denominator bourne-compatible shell features. In
fact, the best practice is to only use features which are common to
both Bourne and CSH-compatible shells. It may come as a shock, but
there are actually more *NIXen than Linux, and many of them don't use
Bash as the default shell.

If you expect portability, you shouldn't be be doing anything that
depends on bash-specific features in your #system()/backtick calls.
If you need to invoke a specific shell, the popen() family of methods
are your friends.

--
Avdi

Home: http:...
Developer Blog: http:.../devblog/
Twitter: http://twitte...
Journal: http://avdi.livej...

ara.t.howard

8/12/2008 2:43:00 PM

0


On Aug 11, 2008, at 11:48 PM, John Carter wrote:

>
> Thus on Debian (and Debian derivatives like Ubuntu) Rubies backtick
> (iff there is a glob or a redirection present) is HARDCODED to /bin/sh
> but will (depending on the users whim) give you dash or bash.


i could easily be wrong, but i have a dim recollection that the
location of sh is a POSIX standard itself.

backticks seem to respect the SHELL var here

cfp:~ > SHELL=tcsh ruby -e' puts `echo $SHELL 2>out` '
tcsh


a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama