[GRASS5] 5.0.2 trashes .grassrc5

I have a recurring error on Grass 5.0.2. Starting with no .grassrc5:

1) run grass5 -text
2) enter Location name, Mapset, and Database in start page
contents of .grassrc5:
GISDBASE: /usr2/grass/data
LOCATION_NAME: globe
MAPSET: PERMANENT

3) run grass
4) quit grass

5) run grass5
Output:
Cleaning up temporary files.....
Starting GRASS ...
awk: illegal field $()
input record number 1, file /export/home/cheg/.grassrc5
source line number 1

Starts gis_set.tcl window and stops.
contents of .grassrc5:
GRASS_GUI: tcltk

6) kill gis_set.tcl window
Output: ERROR: LOCATION_NAME: not set
/usr/local/grass5/etc/Init.sh: GISDBASE: parameter null or not set

7) run grass5 -text
awk: illegal field $()
input record number 1, file /export/home/cheg/.grassrc5
source line number 1

Start screen comes up without Location, Mapset, or Database defined.

8) Reenter Location, Mapset, and Database and start grass
contents of .grassrc5:
GRASS_GUI: text
GISDBASE: /usr2/grass/data
LOCATION_NAME: globe
MAPSET: PERMANENT

9) quit grass
contents of .grassrc5:
GRASS_GUI: text
GISDBASE: /usr2/grass/data
LOCATION_NAME: globe
MAPSET: PERMANENT

10) run grass5
Output:
awk: illegal field $()
input record number 1, file /export/home/cheg/.grassrc5
source line number 1

contents of .grassrc5:
GRASS_GUI: text
GISDBASE: /usr2/grass/data
LOCATION_NAME: globe
MAPSET: PERMANENT

Chris Heg wrote:

I have a recurring error on Grass 5.0.2. Starting with no .grassrc5:

awk: illegal field $()
input record number 1, file /export/home/cheg/.grassrc5
source line number 1

That error is due to this change:

  revision 1.43
  date: 2003/02/27 17:44:53; author: markus; state: Exp; lines: +19 -9
  further changes for white space support

- awk '$1 !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"
+ awk '$ARGS !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"

- awk '$1 !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"
+ awk '$ARGS !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"

I don't understand exactly what was intended in the general case
(changing $1 to $ARGS), but it's clear that this specific case is
wrong: in the "awk" commands, "$1" is an awk variable, not a shell
variable, so it shouldn't have been changed.

I'll fix the specific awk problem myself.

Regarding the more general changes, I'd appreciate it if Markus could
provide some insight into the motivation behind changing $1 to $ARGS.

--
Glynn Clements <glynn.clements@virgin.net>

On Sun, Mar 09, 2003 at 05:19:47AM +0000, Glynn Clements wrote:

Chris Heg wrote:

> I have a recurring error on Grass 5.0.2. Starting with no .grassrc5:

> awk: illegal field $()
> input record number 1, file /export/home/cheg/.grassrc5
> source line number 1

That error is due to this change:

  revision 1.43
  date: 2003/02/27 17:44:53; author: markus; state: Exp; lines: +19 -9
  further changes for white space support

- awk '$1 !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"
+ awk '$ARGS !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"

- awk '$1 !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"
+ awk '$ARGS !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"

I don't understand exactly what was intended in the general case
(changing $1 to $ARGS), but it's clear that this specific case is
wrong: in the "awk" commands, "$1" is an awk variable, not a shell
variable, so it shouldn't have been changed.

I'll fix the specific awk problem myself.

Regarding the more general changes, I'd appreciate it if Markus could
provide some insight into the motivation behind changing $1 to $ARGS.

AFAIK this change should not affect 5.0.2 as it was done in HEAD only.

$ARGS is set in line 49. Probably I have chosen a reserved word?
So far it worked for me/us on Linux.
The underlying idea is white space support as the CVS comment states.
In case of white space the calling script which starts GRASS is
sending several parameters to Init.sh, that's why $ARGS is constructed
in line 49.

Markus

Markus Neteler wrote:

> I don't understand exactly what was intended in the general case
> (changing $1 to $ARGS), but it's clear that this specific case is
> wrong: in the "awk" commands, "$1" is an awk variable, not a shell
> variable, so it shouldn't have been changed.
>
> I'll fix the specific awk problem myself.
>
> Regarding the more general changes, I'd appreciate it if Markus could
> provide some insight into the motivation behind changing $1 to $ARGS.

AFAIK this change should not affect 5.0.2 as it was done in HEAD only.

$ARGS is set in line 49. Probably I have chosen a reserved word?
So far it worked for me/us on Linux.

AFAICT, awk interprets $ARGS as $(ARGS); as the variable ARGS is
undefined (in awk), this is equivalent to $(). It appears that your
version of awk treats that as equivalent to $0 (the entire line),
while Chris' version treats it as a syntax error.

The point is that the $1 in the literal string which is passed to awk
is an awk field reference, not a shell variable (whereas all of the
other occurrences of $1 in the script are shell variables), and
shouldn't have been changed.

The underlying idea is white space support as the CVS comment states.
In case of white space the calling script which starts GRASS is
sending several parameters to Init.sh, that's why $ARGS is constructed
in line 49.

I see what you are trying to do, but it's the wrong approach. The
grass5 script itself needs to be changed to preserve argument
boundaries, e.g.

  exec "$GISBASE/etc/Init.sh" "$GRASS_GUI" "$@"

Actually, the grass5 script should be reduced to just:

  #!/bin/sh
  GISBASE=...
  export GISBASE
  exec "$GISBASE/etc/Init.sh" "$@"

with everything else moved into Init.sh. That will work for every
possible combination of arguments, even those which include embedded
spaces, newlines, quotes etc.

The key point in the above is that the expression "$@" evaluates to
the list of command-line arguments, with argument boundaries
preserved. This is handled as a special-case; there is no way to
obtain the same effect with ordinary variables. This feature exists
precisely to solve this particular problem.

Aside: the Bourne shell's biggest drawback as a general-purpose
programming language is that there is no reliable way to implement
lists. All variables are strings; if you try to represent a list as a
string, with the elements separated by a separator character, it fails
if one of the elements actually contains the separator character.

--
Glynn Clements <glynn.clements@virgin.net>

Yes, the error is in the 2 day old CVS head.

----- Original Message -----
From: "Markus Neteler" <neteler@itc.it>
To: "grass5 developers list" <grass5@grass.itc.it>
Sent: Sunday, March 09, 2003 8:56 AM
Subject: Re: [GRASS5] 5.0.2 trashes .grassrc5

AFAIK this change should not affect 5.0.2 as it was done in HEAD only.

$ARGS is set in line 49. Probably I have chosen a reserved word?
So far it worked for me/us on Linux.
The underlying idea is white space support as the CVS comment states.
In case of white space the calling script which starts GRASS is
sending several parameters to Init.sh, that's why $ARGS is constructed
in line 49.

Markus

_______________________________________________
grass5 mailing list
grass5@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass5

On Sun, Mar 09, 2003 at 06:23:40PM +0000, Glynn Clements wrote:
[...]

I see what you are trying to do, but it's the wrong approach. The
grass5 script itself needs to be changed to preserve argument
boundaries, e.g.

  exec "$GISBASE/etc/Init.sh" "$GRASS_GUI" "$@"

Actually, the grass5 script should be reduced to just:

  #!/bin/sh
  GISBASE=...
  export GISBASE
  exec "$GISBASE/etc/Init.sh" "$@"

with everything else moved into Init.sh. That will work for every
possible combination of arguments, even those which include embedded
spaces, newlines, quotes etc.

I have submitted an update to 5.0/CVS/HEAD for
src/general/init/grass.src
src/general/init/init.sh

according to the suggestions above. White space support should be present
(I tried on Linu only) again.

In fact the script is simpler now.

Markus

Markus Neteler wrote:

> I see what you are trying to do, but it's the wrong approach. The
> grass5 script itself needs to be changed to preserve argument
> boundaries, e.g.
>
> exec "$GISBASE/etc/Init.sh" "$GRASS_GUI" "$@"
>
> Actually, the grass5 script should be reduced to just:
>
> #!/bin/sh
> GISBASE=...
> export GISBASE
> exec "$GISBASE/etc/Init.sh" "$@"
>
> with everything else moved into Init.sh. That will work for every
> possible combination of arguments, even those which include embedded
> spaces, newlines, quotes etc.

I have submitted an update to 5.0/CVS/HEAD for
src/general/init/grass.src
src/general/init/init.sh

according to the suggestions above. White space support should be present
(I tried on Linu only) again.

1. The updated init.sh script still uses the following idiom:

      CMD_LINE_ARGS="$CMD_LINE_ARGS $i "

This is broken, for the reasons outlined in my previous message. Also,
it should no longer be relevant, as the code has been moved into
init.sh.

The correct way to process arguments is to have the cases for -text
and -tcltk use the "shift" command to remove those arguments from the
argument list. At the end of the loop, "$@" will hold the remaining
arguments; there should only be one of these, and it should be
referenced as "$1".

2. You have re-introduced the original awk bug at line 291:

    awk '$CMD_LINE_ARGS !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"

This should be:

    awk '$1 !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"

--
Glynn Clements <glynn.clements@virgin.net>