[GRASS-user] Envtl variables

Hi!

I'm using grass 6.2.3 on ubuntu hardy. I can't get the value
of the grass environmental varaibles. If I do g.gisenv. I get:
alobo@alobo-laptop:~$ g.gisenv
GRASS_GUI=tcltk
GISDBASE=/home/alobo/grass/
LOCATION_NAME=FBBVA
MAPSET=BENI1

but if I do echo $MAPSET I get a white line.

How can I get the values of the environmental variables? I'll
need them for scripts.

Thanks

Agus
--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo@ija.csic.es
http://www.ija.csic.es/gt/obster

Ciao,

2008/5/6 Agustin Lobo <aloboaleu@gmail.com>:

I'm using grass 6.2.3 on ubuntu hardy. I can't get the value
of the grass environmental varaibles. If I do g.gisenv. I get:
alobo@alobo-laptop:~$ g.gisenv
GRASS_GUI=tcltk
GISDBASE=/home/alobo/grass/
LOCATION_NAME=FBBVA
MAPSET=BENI1

but if I do echo $MAPSET I get a white line.

How can I get the values of the environmental variables? I'll
need them for scripts.

use 'eval'

$ eval `g.gisenv`
$ echo $MAPSET
user1

see e.g.

http://trac.osgeo.org/grass/browser/grass/branches/develbranch_6/scripts/db.dropcol/db.dropcol#L89

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

Still nothing, look:

alobo@alobo-laptop:~$ eval 'g.gisenv'
GRASS_GUI=tcltk
GISDBASE=/home/alobo/grass/
LOCATION_NAME=FBBVA
MAPSET=BENI1
alobo@alobo-laptop:~$ echo $MAPSET

alobo@alobo-laptop:~$

Agus

Martin Landa wrote:

Ciao,

2008/5/6 Agustin Lobo <aloboaleu@gmail.com>:

I'm using grass 6.2.3 on ubuntu hardy. I can't get the value
of the grass environmental varaibles. If I do g.gisenv. I get:
alobo@alobo-laptop:~$ g.gisenv
GRASS_GUI=tcltk
GISDBASE=/home/alobo/grass/
LOCATION_NAME=FBBVA
MAPSET=BENI1

but if I do echo $MAPSET I get a white line.

How can I get the values of the environmental variables? I'll
need them for scripts.

use 'eval'

$ eval `g.gisenv`
$ echo $MAPSET
user1

see e.g.

http://trac.osgeo.org/grass/browser/grass/branches/develbranch_6/scripts/db.dropcol/db.dropcol#L89

Martin

--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo@ija.csic.es
http://www.ija.csic.es/gt/obster

Hi,

2008/5/6 Agustin Lobo <Agustin.Lobo@ija.csic.es>:

alobo@alobo-laptop:~$ eval 'g.gisenv'

should be

eval `g.gisenv`

not

eval 'g.gisenv'

Martin

GRASS_GUI=tcltk
GISDBASE=/home/alobo/grass/
LOCATION_NAME=FBBVA
MAPSET=BENI1
alobo@alobo-laptop:~$ echo $MAPSET

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

ok, thanks, it works fine,
but I do not understad it.
Why do we need the eval command?
eval is not mentioned in
http://grass.itc.it/grass62/manuals/html62_user/variables.html

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

Agus

Martin Landa wrote:

Hi,

2008/5/6 Agustin Lobo <Agustin.Lobo@ija.csic.es>:

alobo@alobo-laptop:~$ eval 'g.gisenv'

should be

eval `g.gisenv`

not

eval 'g.gisenv'

Martin

GRASS_GUI=tcltk
GISDBASE=/home/alobo/grass/
LOCATION_NAME=FBBVA
MAPSET=BENI1
alobo@alobo-laptop:~$ echo $MAPSET

--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo@ija.csic.es
http://www.ija.csic.es/gt/obster

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

Paul Kelly wrote:

> 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,

FWIW, "eval `g.gisenv`" will create shell variables; they only become
environment variables if they're explictly "export"ed.

--
Glynn Clements <glynn@gclements.plus.com>