[GRASS-dev] Re: grass-dev Digest, Vol 10, Issue 46

Hamish hamish_nospam at yahoo.com
Mon Feb 19 23:44:58 EST 2007


> Michael Barton wrote:
> > Probably showing undue ignorance, but I have to ask. How can we know
> > if something is bash specific or more generally POSIX-compatible?

ash -n scriptname

$ ash -n r.tileset
r.tileset: 258: Syntax error: Bad for loop variable

$ cat -n r.tileset | grep '^.* 258'
   258          for ((min_i=0;min_i<min_n;min_i+=1)) ; do

(( )) is a Bashism. possible replacement:

min_i=0
while [ min_i -lt min_n ] ; do
   ...
   ...

   min_i=`expr $min_i + 1`
done

but the r.tileset script makes Heavy use of SIZE_ARRAY[0]="" style
Bash arrays, so I fear it will need to be totally rewritten or
declared "Bash only".  Is this enough for such a test?

if [ "`basename $SHELL`" != "bash" ] ; then
   echo "$0: This script requires Bash" 2>&1
   exit 1
fi

(apparently not, starting ash from the bash prompt preserved $SHELL
as /bin/bash; but maybe it helps catch real world cases? I guess the
real issue is testing what the /bin/sh symlink points to. I guess
Init.sh could run a little test and set GRASS_HAVE_BASH=1, but it
is better to just fix r.tileset)


To my surprise SUBMITTING_SCRIPTS didn't say anything about Bashisms.
Fixed in 6.3 CVS.

scripts/r.in.wms/wms.request has SIZE_ARRAY[0]="", but AFAICT it goes
unused? Otherwise r.in.wms is ok?


Glynn Clements wrote:
> Run it under a less "enhanced" shell such as ash or dash.
> 
> I suspect that this may be the "real" motivation for using dash for
> /bin/sh on Ubuntu. Using bash as /bin/sh is asking for people to write
> bash-specific scripts (and putting #!/bin/sh at the top of them).


see  https://wiki.ubuntu.com/DashAsBinSh

"Ubuntu switched from Bash to Dash in Edgy to noticeably shorten boot
times. Apparently booting involves forking a LOT of shells, and Bash is
big, featureful, and slow (and has the most convoluted syntax of any
programming language that I know -- including APL -- but I digress...)"
--bronson  http://lwn.net/Articles/220255/

The Ubuntu bug report for this is a passionate meeting of idealogues
and pragmatists, worthy of classic usenet:
  https://launchpad.net/ubuntu/+source/dash/+bug/61463
  http://www.ubuntuforums.org/archive/index.php/t-221769.html


"As the symlink is adjustable via a debconf question, any users who do
not wish to have a POSIX shell as the default can run dpkg-reconfigure
dash and restore bash."

Also on Debian [so prob Ubuntu as well] there is "update-alternatives"
to change where /bin/sh points to.


In other circles, the new Debian installer will use [d]ash as part of a
micro-deb (udeb) package. The motivation is that this is much smaller
than bash and can be included on the floppy disk installer -- just the
bare minimum to get the network install started. The package description
also mentions that it depends on less things, so is less likely to be
problematic on a machine suffering library hell/anemia.

http://packages.debian.org/unstable/debian-installer/dash-udeb

On Debian bash is a required package, and AFAICT it is on Ubuntu Edgy+
as well.


Hamish




More information about the grass-dev mailing list