g.message(1)
π¬ g.message β the GRASS way to say things π¬
okay bestie, this is g.message(1) from the GRASS GIS User's Manual, and it's literally the module you use to talk to the user from inside a script. no cap.
β¨ NAME β¨
g.message β prints a message, warning, progress info, or fatal error in the GRASS way.
fr fr, this module should be used in scripts for messages served to user. π
π·οΈ KEYWORDS π·οΈ
general, support, scripts
π SYNOPSIS π
g.message
g.message --help
g.message [-wedpiv] message=string [debug=integer] [--help]
[--verbose] [--quiet] [--ui]
π© Flags π©
-wβ print the message as a warning β οΈ-eβ print the message as a fatal error π-dβ print the message as a debug message π-pβ print the message as progress info π-iβ print the message in all modes except quiet mode. it's printed onGRASS_VERBOSE>=1π«Ά-vβ print the message only in verbose mode. it's printed only onGRASS_VERBOSE>=3π£οΈ--helpβ print usage summary π--verboseβ verbose module output--quietβ quiet module output π€«--uiβ force launching GUI dialog π₯οΈ
π§© Parameters π§©
message=string[required] β text of the message to be printed. message is printed onGRASS_VERBOSE>=2πdebug=integerβ level to use for debug messages- Options:
0-5 - Default:
1
- Options:
πΈ DESCRIPTION πΈ
g.message prints a message, warning, progress info, or fatal error in the GRASS GIS way. the way that it's meant to be used is inside Shell/Perl/Python scripts, so the author does not need to use the echo program. the whole slay of g.message is that it formats messages just like every other GRASS module does, and that its functionality is influenced by the GRASS_VERBOSE and GRASS_MESSAGE_FORMAT environment variables. π
you can use this program for standard informative messages, and also for warnings (the -w flag) and fatal errors (the -e flag). and for debugging purposes, the -d flag will cause g.message to print a debugging message at the given level. π
π NOTES π
messages containing "=" must use the full message= syntax so the parser doesn't get confused. like, the parser is doing its best, be nice to it. π
if you want a long message (multi-line) to be dealt with as a single paragraph, use a single call to g.message with the text split in the script using the backslash as the last character. (in shell scripts, don't close the "quote".) π§΅
a blank line may be obtained with:
g.message message=""
redundant whitespace will be stripped away. βοΈ
it's advisable to single quote the messages that are to be printed literally. it prevents a number of characters (most notably, space and the dollar sign '$') from being treated specifically by the shell. π‘οΈ
when it's necessary to include, for example, a variable's value as part of the message, the double quotes may be used, which do not deprive the dollar sign of its special variable-expansion powers. π«
while it is known that the interactive Bash instances may treat the exclamation mark '!' character specifically (making single quoting of it necessary), it shouldn't be the case for the non-interactive instances of Bash. nonetheless, to avoid context-based confusion later on you are encouraged to single-quote messages that do not require $VARIABLE expansion. π
π Usage in Python scripts π
the GRASS Python Scripting Library defines special wrappers for g.message:
debug()forg.message -derror()forg.message -efatal()forg.message -e + exit()info()forg.message -imessage()forg.messageverbose()forg.message -vwarning()forg.message -w
note: the Python tab in the wxGUI can be used for entering the following sample code: π
import grass.script as gcore
gcore.warning("This is a warning")
is identical with
g.message -w message="This is a warning"
π VERBOSITY LEVELS π
controlled by the "GRASS_VERBOSE" environment variable. typically this is set using the --quiet or --verbose command line options.
0β only errors and warnings are printed1β progress messages are printed2β all module messages are printed3β additional verbose messages are printed
π DEBUG LEVELS π
controlled by the "DEBUG" GRASS gisenv variable (set with g.gisenv). recommended levels:
1β message is printed once or few times per module3β each row (raster) or line (vector)5β each cell (raster) or point (vector)
π¬ EXAMPLES π¬
this basic example prints the message "hello" in the console:
g.message message="hello"
to print a message as an error message, use the -e flag:
g.message -e message="my error"
to print a message highlighted as a debug message ("D0/0: debug") in the console, use the -d flag. optionally the debug level can be defined (see also g.gisenv for details):
# Levels: (recommended levels)
# 0 - silence
# 1 - message is printed once or few times per module
# 3 - each row (raster) or line (vector)
# 5 - each cell (raster) or point (vector)
g.message -d message="debug" debug=0
to print a message highlighted as a warning message ("WARNING: my warning") in the console, use the -w flag:
g.message -w message="my warning"
π SEE ALSO π
- GRASS variables and environment variables
g.gisenv,g.parser
ποΈ AUTHOR ποΈ
Jachym Cepicky
π» SOURCE CODE π»
available at: g.message source code (history)
accessed: Saturday Jan 17 05:40:39 2026
Main index | General index | Topics index | Keywords index | Graphical index | Full index
okay that's the whole thing bestie, and now the cute sign-off: this was GRASS GIS 8.4.2, Β© 2003-2025 GRASS Development Team, straight out of the GRASS GIS 8.4.2 Reference Manual, and honestly? iconic. periodt. πβ¨π¦
π¦ where this page comes from
- fedora 44: grass 8.4.2-4.fc44 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms