[GRASS-dev] [bug #5499] (grass) bash scripts starting with #!/bin/sh

Hamish hamish_nospam at yahoo.com
Sun Mar 18 19:49:35 EDT 2007


[this matters as the new Ubuntu uses [d]ash for #!/bin/sh not bash]

Maciek Sieczka via RT wrote:
> Another bunch of possible bashism, in regard too Hamish'es hints on
> how to avoid them.

(as collected from this list mostly)

> Hamish wrote:
> > use "=" not "==" for string compares
> 
> These do not conform:
> 
> d.correlate:  if [ "$name" == "" ] ; then

# use -z to test if string is zero-length, -n to test if non-zero length
if [ -z "$name" ] ; then

> d.correlate:if [ "$ok" == "no" ] ; then

# only use a single "=" for string compares
if [ "$ok" = "no" ] ; then

> d.polar:if [ $TOTALVALIDNUMBER == 0 ] ; then

# use -eq integer compare
if [ "$TOTALVALIDNUMBER" -eq 0 ] ; then

> d.vect.thematic:    if [ "`db.columns table=$table database=$database
>   driver=$driver | grep -i grassrgb`" == "" ] ; then

Use -z. Note d.vect.thematic also uses "let" in a several places which
needs to be changed to `expr`.

> g.mlist:  if [ "$itype" == "all" ] ; then

=

> r.fillnulls:r.mapcalc "MASK=if($TMP1.buf==2,1,null())"

"==" is ok within a r.mapcalc expression. Not a bug.

> r.plane:         if (dist==0) {

-eq

> r.plane:        if (typeflag==""){

-z

> v.rast.stats: r.mapcalc "MASK=if(${VECTOR}_${TMPNAME} == $i, 1,
> null())" 2> /dev/null

ok within r.mapcalc. Not a bug.


> Also, I guess (and only guess) that -+ and += would fail for non-Bash.
> There are some in r.tileset:

As Glynn already noted, r.tileset is written as a bash program, not a
unix shell script, and it is more work than I want to undertake to
rewrite it.



Hamish




More information about the grass-dev mailing list