Tom Buskey | 1 Oct 2007 16:30

Re: GOTCHA in Ubuntu - broken shell



On 10/1/07, Ben Scott <dragonhawk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
On 10/1/07, Tom Buskey <tom-7upyCGkO2WZ7tPAFqOLdPg@public.gmane.org> wrote:
> Scripting non-bourne shell stuff with #!/bin/sh at the top *should* break.

  Ah, yes, maximum pain as a design goal.  :-(

What I'm saying is #!/bin/sh should run like #!/bin/sh.  export VAR=value doesn't work in bourne shell.  So if you put that in a bourne shell script with #!/bin/sh, then it should fail.  If you want it to succeed, use a shell that accepts that syntax, such as #!/bin/bash or #!/bin/ksh.

I've seen scripts that start w/o #!/bin/sh by people with a default csh.  They run ok in their environment, but someone running bash breaks them.  They're coding csh so #!/bin/csh should be at the top.  It'd expect csh scripts to fail if #!/bin/sh was at the top because sh runs bourne shell.
 

> If you want bash or ksh, use #!/bin/bash or #!/bin/ksh.

  What about an extension feature that exists in more than one
implementation, but is not part of POSIX?
  What about the "range of acceptable implementations" problem of the
POSIX standard that Fran Fadden pointed out?

I don't think I can address this so I won't.

> If it doesn't exist in /bin, put it there where it belongs.

  So now shell scripts are totally unportable.

No, #!/bin/sh is bourne shell.  /bin/bash is bash.  If you need your bash script to work on, say SunOS or Solaris 7, install /bin/bash so it will work.  So maybe bash scripts are not portable, but they never really were.  Maybe they are on linux where #!/bin/bash always exists.

Look at perl.  Nowadays it is on most systems.  It used to have to be added.  It was in /bin, /usr/local/bin, /opt/sfw/bin.  When you go on a new system, you can't ensure that all the modules your script needs are installed so you have to add them.  Maybe you're on Solaris 8 with perl 5.0003 and perl 5.8 was installed in /usr/local/bin with all the modules.
 

> I've been shell scripting for awhile on multiple OSen.

  Yah, and it sucks.  Linux should aim to succeed where other *nixes
fail, and not suck.

I agree too.  I don't think making /bin/sh run bashism would be any different from linking /bin/sh to /bin/csh.

My point is that expecting #!/bin/sh to act like bash or ksh or csh is wrong.  It's like expecting grape juice to taste like wine.
 

  I don't want a sequel to the Unix Wars.

Who does?  Thank goodness environments have converged a bit.  /bin/perl, /bin/bash exist in Solaris, Linux, Cygwin, xBSD and (I think) MacOSX.

_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@...
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/

Gmane