[GRASS-dev] [GRASS GIS] #81: scripts: "echo -n" not portable

#81: scripts: "echo -n" not portable
---------------------+------------------------------------------------------
Reporter: hamish | Owner: grass-dev@lists.osgeo.org
     Type: defect | Status: new
Priority: blocker | Milestone: 6.3.0
Component: default | Version: svn-trunk
Keywords: |
---------------------+------------------------------------------------------
Hi,

apparently "echo -n" is not portable, it fails on OSX 10.5

I removed it from scripts/r.in.wms/wms.request, but these remain:
{{{
scripts$ grep -rIl "echo -n" * | grep -v '/.svn/'
d.vect.thematic/d.vect.thematic
i.in.spotvgt/i.in.spotvgt
r.tileset/r.tileset
v.db.renamecol/v.db.renamecol
}}}

v.db.renamecol is a false positive:
{{{
v.db.renamecol/v.db.renamecol: # 'echo -n' (output as string, ie with no
newline) is apparently not portable.
}}}

Hamish

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/81&gt;
GRASS GIS <http://grass.osgeo.org>
GRASS Geographic Information System (GRASS GIS) - http://grass.osgeo.org/

#81: scripts: "echo -n" not portable
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: hamish
      Type: defect | Status: assigned
  Priority: blocker | Milestone: 6.3.0
Component: default | Version: svn-trunk
Resolution: | Keywords:
----------------------+-----------------------------------------------------
Changes (by hamish):

  * status: new => assigned
  * owner: grass-dev@lists.osgeo.org => hamish
* cc: grass-dev@lists.osgeo.org (added)

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/81#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>
GRASS Geographic Information System (GRASS GIS) - http://grass.osgeo.org/

#81: scripts: "echo -n" not portable
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: hamish
      Type: defect | Status: assigned
  Priority: blocker | Milestone: 6.3.0
Component: default | Version: svn-trunk
Resolution: | Keywords:
----------------------+-----------------------------------------------------
Comment (by kyngchaos):

If using echo without -n doesn't work for some reason, I found
that/bin/echo on OSX 10.5 DOES work, it's the shell version of echo on
10.5 that doesn't have -n.

The echo man page suggests using printf to suppress the newline char, for
portability.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/81#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>
GRASS Geographic Information System (GRASS GIS) - http://grass.osgeo.org/

#81: scripts: "echo -n" not portable
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: hamish
      Type: defect | Status: assigned
  Priority: blocker | Milestone: 6.3.0
Component: default | Version: svn-trunk
Resolution: | Keywords:
----------------------+-----------------------------------------------------
Comment (by hamish):

d.vect.thematic and i.in.spotvgt are updated in SVN/trunk, if someone who
uses those could test please? then we can backport for 6.3.0.

I am not sure about r.tileset:
{{{
Index: r.tileset/r.tileset

--- r.tileset/r.tileset (revision 30465)
+++ r.tileset/r.tileset (working copy)
@@ -189,15 +189,11 @@
  Lookup_Mac() {

  # Assignment Command Statement Builder
+# $1 is Source name
+# $3 is Destination name

- echo -n 'eval '
- echo -n "$3" # Destination name
- echo -n '=${'
- echo -n "$1" # Source name
- echo -n "[$2]}"
+ echo "eval $3=${$1[$2]}"

-# That could all be a single command.
-# Matter of style only.
  }

  # Lookup_Mac
}}}

?will that work?

newline suppression via printf shouldn't be needed....

Hamish

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/81#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>
GRASS Geographic Information System (GRASS GIS) - http://grass.osgeo.org/

On Thu, 6 Mar 2008, GRASS GIS wrote:

#81: scripts: "echo -n" not portable
----------------------+-----------------------------------------------------
Reporter: hamish | Owner: hamish
     Type: defect | Status: assigned
Priority: blocker | Milestone: 6.3.0
Component: default | Version: svn-trunk
Resolution: | Keywords:
----------------------+-----------------------------------------------------
Comment (by kyngchaos):

If using echo without -n doesn't work for some reason, I found
that/bin/echo on OSX 10.5 DOES work, it's the shell version of echo on
10.5 that doesn't have -n.

The echo man page suggests using printf to suppress the newline char, for
portability.

Remember also we have $GISBASE/etc/echo, for cases where a cross-platform identically-behaved echo command is required. It accepts both -n to suppress a newline, and -e to echo to stderr rather than stdout.

Paul

GRASS GIS wrote:

- echo -n 'eval '
- echo -n "$3" # Destination name
- echo -n '=${'
- echo -n "$1" # Source name
- echo -n "[$2]}"
+ echo "eval $3=${$1[$2]}"

?will that work?

I wouldn't count on it; the shell may attempt to evaluate the ${...}
part.

I suspect that may be why it was output in pieces in the first place.

Try:
  echo 'eval '"$3"'=${'"$1""[$2]}"

--
Glynn Clements <glynn@gclements.plus.com>

#81: scripts: "echo -n" not portable
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: hamish
      Type: defect | Status: assigned
  Priority: blocker | Milestone: 6.3.0
Component: default | Version: svn-trunk
Resolution: | Keywords:
----------------------+-----------------------------------------------------
Comment (by hamish):

Glynn wrote:
> I wouldn't count on it; the shell may attempt to evaluate the ${...}
> part.
>
> I suspect that may be why it was output in pieces in the first place.
>
> Try:
> echo 'eval '"$3"'=${'"$1""[$2]}"

I glazed over last time I tried to follow that, not realizing that it is
just a straight concatenation of the series of 'echo -n' lines. So no less
safe than what is currently there.

Paul also suggested using GRASS's own $GISBASE/etc/echo which respects -n,
which could be clearer but doesn't help us ween ourselves off of
workaround apps.

I am currently leaning towards Glynn's suggestion as it requires a smaller
toolset.

I had guessed that in OSX 10.5 /bin/echo did not like -n but the bash
shell was ok with it (and so !/bin/bash'ing r.tileset apparently worked
without modification). Rereading William's comment in this bug report
suggests the opposite it true. Best to just get rid of the -n rather than
spend time trying to work out why..

Hamish

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/81#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>
GRASS Geographic Information System (GRASS GIS) - http://grass.osgeo.org/

#81: scripts: "echo -n" not portable
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: hamish
      Type: defect | Status: assigned
  Priority: blocker | Milestone: 6.3.0
Component: default | Version: svn-trunk
Resolution: | Keywords:
----------------------+-----------------------------------------------------
Comment (by hamish):

'echo -n' removed from r.tileset in r30616.

d.vect.thematic, i.in.spotvgt, and r.tileset (r.in.wms) now need testing
in trunk before backporting them to the 6.3.0 branch and closing this bug.

Hamish

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/81#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>
GRASS Geographic Information System (GRASS GIS) - http://grass.osgeo.org/

#81: scripts: "echo -n" not portable
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: hamish
      Type: defect | Status: assigned
  Priority: blocker | Milestone: 6.3.0
Component: default | Version: svn-trunk
Resolution: | Keywords:
----------------------+-----------------------------------------------------
Comment (by neteler):

I have tested i.in.spotvgt, it works. Backported to 6.3.0-relbranch as
[c30621].

Markus

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/81#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>
GRASS Geographic Information System (GRASS GIS) - http://grass.osgeo.org/

#81: scripts: "echo -n" not portable
----------------------+-----------------------------------------------------
  Reporter: hamish | Owner: hamish
      Type: defect | Status: closed
  Priority: blocker | Milestone: 6.3.0
Component: default | Version: svn-trunk
Resolution: fixed | Keywords:
----------------------+-----------------------------------------------------
Changes (by hamish):

  * status: assigned => closed
  * resolution: => fixed

Comment:

d.vect.thematic, r.tileset, and r.in.wms stuff backported to 6_3 release
branch.
(fingers crossed)

r30634, r30635, r30636, r30637.

closing bug.

Hamish

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/81#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>
GRASS Geographic Information System (GRASS GIS) - http://grass.osgeo.org/