g.message(1grass)
π g.message β the GRASS manual page, but make it make sense π
okay bestie, gather round, because this is the little module your whole script has been waiting for. It lives in the GRASS User's Manual, and its whole job is: prints a message, warning, progress info, or fatal error in the GRASS way. And the vibe check on it? This module should be used in scripts for messages served to user. Basically it's the glow-up echo wishes it was.
β¨ NAME β¨
g.message β prints a message, warning, progress info, or fatal error in the GRASS way.
This module should be used in scripts for messages served to user. fr fr, that's its entire personality and it ate. π
π 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. Message is printed onGRASS_VERBOSE>=1-vβ print the message only in verbose mode. Message is 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>=2debug=integerβ level to use for debug messages. Options:0-5Default:1
π DESCRIPTION π
g.message prints a message, warning, progress info, or fatal error in the GRASS way. This program is to be used in Shell/Perl/Python scripts, so the author does not need to use the echo program. The advantage of g.message is that it formats messages just like other GRASS modules do and that its functionality is influenced by the GRASS_VERBOSE and GRASS_MESSAGE_FORMAT environment variables.
The program can be used for standard informative messages as well as warnings (the -w flag) and fatal errors (the -e flag). For debugging purposes, the -d flag will cause g.message to print a debugging message at the given level. It's giving professional, it's giving consistent, and honestly? obsessed. π
π«Ά 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 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 said "no extra drama." π )
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 is 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. Bestie, just single-quote it. Future you will thank present you. π
π Usage in Python scripts π
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)
Latest change: Friday Aug 08 09:39:19 2025 in commit: ed72c71d8580e872cd6fd345c84a15c324764465
Main index | General index | Topics index | Keywords index | Graphical index | Full index
and that's the whole page, bestie π«Ά shoutout to the GRASS Development Team for the copyright, Β© 2003-2026, sitting pretty in the GRASS 8.5.0 Reference Manual β this is GRASS 8.5.0, no cap. go print some messages, you're gonna slay. πβ¨π
π¦ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 Β· GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· 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