variables(1grass)

variables1grass

GRASS variables and environment variables

A variable in scripting is a symbolic name that holds data which can be used and modified during script execution. Variables allow scripts to store and manipulate values dynamically, making them more flexible and reusable. In GRASS GIS, there are two types of variables:

•

shell environment variables,

•

GRASS gisenv variables.

There are a number of shell environment variable groups:

•

variables for rendering

•

variables for internal use

Note: Any setting which needs to be modifiable by a GRASS module (e.g. MONITOR by d.mon) has to be a GRASS gisenv variable.

Setting shell environment variables

Setting shell environment variables depends on the shell being used:

Bash:

export VARIABLE=value

Csh:

setenv VARIABLE value

Cmd.exe (Windows):

set VARIABLE=value

To set up shell environment variables permanently:

•

To get personal BASH shell definitions (aliases, color listing option, ...) into GRASS, store them in:
$HOME/.grass8/bashrc

•

To get personal CSH shell definitions (aliases, color listing option, ...) into GRASS, store them in:
$HOME/.grass8/cshrc

Setting GRASS gisenv variables

Use g.gisenv within GRASS. This permanently predefines GRASS variables in the $HOME/.grass8/rc file (Linux, Mac, BSD, ...) or in the %APPDATA%\Roaming\GRASS8\rc file (Windows) after the current GRASS session is closed.

Usage:

g.gisenv set="VARIABLE=VALUE"

It looks unusual with two equals signs, but g.gisenv serves dual duty for getting and setting GRASS variables.

If the user just specifies a variable name, it defaults to get mode. For example:

g.gisenv MAPSET
PERMANENT

List of selected GRASS gisenv variables

[ Use g.gisenv to get/set/unset/change them ]

DEBUG

[entire GRASS]
sets level of debug message output (0: no debug messages)

g.gisenv set=DEBUG=0
WX_DEBUG

[wxGUI]
sets level of debug message output for wxGUI (0: no debug messages, 1-5 debug levels)

GISDBASE

initial database

GIS_LOCK

lock ID to prevent parallel GRASS use,
process id of the start-up shell script

GUI

See GRASS_GUI environmental variable for details.

LOCATION

full path to project (previously called location) directory

LOCATION_NAME

initial project name

MAPSET

initial mapset

MEMORYMB

[entire GRASS with focus on raster related data processing]
sets the maximum memory to be used (in MB), i.e. the cache size for raster rows

# set to 6 GB (default: 300 MB)
g.gisenv set="MEMORYMB=6000"
NPROCS

sets the number of threads for parallel computing

# set to use 12 threads (default: 1)
g.gisenv set="NPROCS=12"
OVERWRITE

[all modules]
toggles map overwrite.

•

0 - maps are protected (default),

•

1 - maps with identical names will be overwritten.

This variable is automatically created by g.parser so that the --overwrite option will be inherited by dependent modules as the script runs. Setting either the GRASS_OVERWRITE environment variable or the OVERWRITE gisenv variable detailed below will cause maps with identical names to be overwritten.

Source code

Available at: GRASS variables and environment variables source code (history)

Accessed: Monday Feb 24 17:50:01 2025

Main index | Topics index | Keywords index | Graphical index | Full index

© 2003-2025 GRASS Development Team, GRASS GIS 8.4.1 Reference Manual

Releases

10 releases since Debian 4.0 (Etch); the text changed 9 times.

  1. 4.0
  2. 5.0
  3. 6.0
  4. 7
  5. 8
  6. 9
  7. 10
  8. 11
  9. 12
  10. 13

From grass-doc 8.4.1-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.