Opened 14 years ago

Closed 14 years ago

#81 closed defect (fixed)

scripts: "echo -n" not portable

Reported by: hamish Owned by: hamish
Priority: blocker Milestone: 6.3.0
Component: Default Version: svn-trunk
Keywords: Cc: grass-dev@…
CPU: Unspecified Platform: Unspecified



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

I removed it from scripts/, but these remain:

scripts$ grep -rIl "echo -n" * | grep -v '/.svn/'

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.


Change History (7)

comment:1 Changed 14 years ago by hamish

Cc: grass-dev@… added
Owner: changed from grass-dev@… to hamish
Status: newassigned

comment:2 Changed 14 years ago 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.

comment:3 Changed 14 years ago by hamish

d.vect.thematic and 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....


comment:4 Changed 14 years ago 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.


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..


comment:5 Changed 14 years ago by hamish

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

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


comment:6 Changed 14 years ago by neteler

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


comment:7 Changed 14 years ago by hamish

Resolution: fixed
Status: assignedclosed

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

r30634, r30635, r30636, r30637.

closing bug.


Note: See TracTickets for help on using tickets.