[GRASS-user] Envtl variables

Paul Kelly paul-grass at stjohnspoint.co.uk
Tue May 6 16:48:09 EDT 2008


On Tue, 6 May 2008, Agustin Lobo wrote:

> ok, thanks, it works fine,
> but I do not understad it.

The reason for the confusion is the variables you refer to are *not* in 
fact environment variables, but GRASS variables. GRASS variables are 
accessed and set using the g.gisenv command. In general, variables that 
need to be able to be changed by GRASS modules during a session are stored 
as GRASS variables, since a GRASS module cannot change environment 
variables.

> Why do we need the eval command?

You don't *need* it; it is a convenience to convert all the GRASS 
variables into environment variables. IMHO I don't think it is a good 
solution to access GRASS variables this way because:
a) it creates as many new environment variables as there are GRASS 
variables, when you perhaps only needed to access one of them, and it has 
the possiblity of overwriting existing environment variables without 
warning should the name of one of them happen to be the same as the name 
of a GRASS variable, and
b) the environment variables created in this way are just copies and won't 
be updated when the underlying GRASS variables change, so could lead to 
inaccuracies unless you run eval `g.gisenv` every time you need to access 
a variable.

If you just need one variable, e.g. MAPSET, the preferred way to access it 
is like this:
`g.gisenv MAPSET`

The backticks `...` substitute the output of the command enclosed by them.

> eval is not mentioned in
> http://grass.itc.it/grass62/manuals/html62_user/variables.html

No, but it shows you how to use g.gisenv to access the variables so that 
is OK. I always thought of the eval `g.gisenv` trick as a hack which 
was a quick way to fix up old GRASS scripts that relied on GISDBASE, 
MAPSET etc. being present as environment variables.

> Also, at the beginning of the script
> that you mentioned,
> $GISDBASE is used not having
> called eval `g.gisenv`, why?

If you look closely you will see that the variable referred to there is 
$GISBASE, not $GISDBASE. GISBASE *is* an environment variable - it refers 
to the base location of the GRASS installation in the filesystem (which 
cannot change during a running GRASS session). GISDBASE refers to the 
location of the current GRASS database (i.e. collection of locations), 
which is allowed to change during a session, thus it is a GRASS variable.

Hope this explanation is useful.

Paul


More information about the grass-user mailing list