[GRASS-user] v.rast.stats2 bug?
Hamish
hamish_b at yahoo.com
Thu Mar 3 03:54:47 EST 2011
Markus wrote:
> I can confirm this bug.
>
> The offending line is
> sed -e '1d' "$STATSTMP" | awk -F "|" '{printf "\nUPDATE '${TABLE}' SET
> '${col[0]}' = %i , '${col[1]}' = %.2f , '${col[2]}' = %.2f,
> '${col[3]}' = %.2f , '${col[4]}' = %.2f , '${col[5]}' = %.2f ,
> '${col[6]}' = %.2f , '${col[7]}' = %.2f , '${col[8]}' = %.2f WHERE
> '${KEYCOL}' = %i;", $2,$3,$4,$5,$6,$7,$8,$9,$10,$1}'
...
> Actually I don't know how to fix the use of col[1] etc. (I
> tried a while).
it is trying to use shell $VARIABLES inside 'single quotes', so the $ is
treated literally instead of getting substituted.
the awk string either needs to be using double quotes like "{printf( .. )}"
or (better) you need to pass each variable to awk on the command line using
the -v flag:
-v var=val
--assign var=val
Assign the value val to the variable var, before execution
of the program begins. Such variable values are available
to the BEGIN block of an AWK program.
thus
$ TABLE=abc
$ awk -v TBL="$TABLE" 'BEGIN {print TBL}'
abc
(BEGIN is used to avoid it waiting for stdin)
...also quoting like ${TABLE} does nothing in this situation besides
clutter the readability. "quotes" must to used to protect from spaces in
the string:
$ VAL="a b"
$ ls "$VAL"
ls: a b: No such file or directory
$ ls ${VAL}
ls: a: No such file or directory
ls: b: No such file or directory
$ ls ${VAL}_123
ls: a: No such file or directory
ls: b_123: No such file or directory
$ ls "${VAL}_123"
ls: a b_123: No such file or directory
Hamish
More information about the grass-user
mailing list