[GRASS-dev] Re: [GRASS-user] bug in v.db.renamecol

Markus Neteler wrote:

http://trac.osgeo.org/grass/changeset/30007

...

+ # strangely "" counts as 1
+ NAMELEN=`echo "$newcol" | wc -c | awk '{print $1}'`
+ if [ "$NAMELEN" -gt 11 ] ; then

the extra char is due to the newline:

$ echo "" | wc -c
1
$ echo -n "" | wc -c
0

For v.db.renamecol + SQLite and DBF, should we add extra checks like
'v.info -c' or even compare before/after v.db.select counts to check
that new column is there and contains data before calling v.db.dropcol?

I guess it's a matter of paranoia vs. wasted redundant effort how far
you go with that.

Hamish

      ____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping

On Feb 8, 2008 12:06 AM, Hamish <hamish_b@yahoo.com> wrote:

Markus Neteler wrote:
> http://trac.osgeo.org/grass/changeset/30007
...
> + # strangely "" counts as 1
> + NAMELEN=`echo "$newcol" | wc -c | awk '{print $1}'`
> + if [ "$NAMELEN" -gt 11 ] ; then

the extra char is due to the newline:

$ echo "" | wc -c
1
$ echo -n "" | wc -c
0

ah, right.
Question: is "-n" portable? I darkly remember some issue.

Markus

For v.db.renamecol + SQLite and DBF, should we add extra checks like
'v.info -c' or even compare before/after v.db.select counts to check
that new column is there and contains data before calling v.db.dropcol?

I guess it's a matter of paranoia vs. wasted redundant effort how far
you go with that.

Hamish

Markus Neteler <neteler@osgeo.org> writes:

[...]

>> the extra char is due to the newline:

>> $ echo "" | wc -c 1 $ echo -n "" | wc -c 0

> ah, right. Question: is "-n" portable? I darkly remember some issue.

  It's mandated by POSIX at least [1]. Besides, it's already used
  widely in the GRASS scripts:

grass $ grep -rF '[ -n ' scripts/
... numerous...
grass $

  One may also use [ x"$varn" != x ] instead, but I'd be against
  such a practice (unless for a good reason.)

[...]

[1] http://www.opengroup.org/onlinepubs/009695399/utilities/test.html