Paul Kelly wrote:

> >>> I noticed parts of the script may be a bit fragile/inefficient, which is
> >>> of concern for a module mainly intended as a scripting tool.
> >>>
> >>> - The script relies on "echo -n"; not portable?
> >
> >> Nope. According to the official specification, echo doesn't accept any
> >> switches. OTOH, the GNU version doesn't support the \c sequence. IOW,
> >> there is no portable way to echo a string without appending a newline.
> 
> What about the echo that is included with GRASS: $GISBASE/etc/echo?

That would work, but it could have a substantial performance hit, as
it can be executed twice per name ("echo" is normally a shell
built-in).

One solution would be to use "$echo", and set it to either "echo" or
"$GISBASE/etc/echo" depending upon whether the default echo command
understands the -n switch. Patch attached.

-- 
Glynn Clements <[EMAIL PROTECTED]>

--- scripts/g.mlist/g.mlist~    2007-09-11 16:19:42.000000000 +0100
+++ scripts/g.mlist/g.mlist     2007-09-11 20:34:45.000000000 +0100
@@ -55,6 +55,12 @@
 #% required : no
 #%end
 
+if [ "`echo -n foo | wc -l`" = 0 ] ; then
+    echo=echo
+else
+    echo="$GISBASE/etc/echo"
+fi
+
 do_list() {
     if [ ! "$search" ] ; then
        search="."
@@ -80,11 +86,11 @@
            if [ -z "$sep" ] ; then
                echo
            else
-               echo -n "$sep"
+               "$echo" -n "$sep"
            fi
         fi
         start=1
-        echo -n "$i$MAPSET"
+        "$echo" -n "$i$MAPSET"
     done
 }
 
_______________________________________________
grass-dev mailing list
[email protected]
http://grass.itc.it/mailman/listinfo/grass-dev

Reply via email to