1g.message(1)                GRASS GIS User's Manual               g.message(1)
2
3
4

NAME

6       g.message   -  Prints a message, warning, progress info, or fatal error
7       in the GRASS way.
8       This module should be used in scripts for messages served to user.
9

KEYWORDS

11       general, support, scripts
12

SYNOPSIS

14       g.message
15       g.message --help
16       g.message [-wedpiv] message=string  [debug=integer]   [--help]  [--ver‐
17       bose]  [--quiet]  [--ui]
18
19   Flags:
20       -w
21           Print message as warning
22
23       -e
24           Print message as fatal error
25
26       -d
27           Print message as debug message
28
29       -p
30           Print message as progress info
31
32       -i
33           Print message in all modes except of quiet mode
34           Message is printed on GRASS_VERBOSE>=1
35
36       -v
37           Print message only in verbose mode
38           Message is printed only on GRASS_VERBOSE>=3
39
40       --help
41           Print usage summary
42
43       --verbose
44           Verbose module output
45
46       --quiet
47           Quiet module output
48
49       --ui
50           Force launching GUI dialog
51
52   Parameters:
53       message=string [required]
54           Text of the message to be printed
55           Message is printed on GRASS_VERBOSE>=2
56
57       debug=integer
58           Level to use for debug messages
59           Options: 0-5
60           Default: 1
61

DESCRIPTION

63       This  program is to be used in Shell/Perl/Python scripts, so the author
64       does not need to use the echo program. The advantage  of  g.message  is
65       that  it formats messages just like other GRASS modules do and that its
66       functionality is influenced by the GRASS_VERBOSE and GRASS_MESSAGE_FOR‐
67       MAT environment variables.
68
69       The  program  can  be used for standard informative messages as well as
70       warnings (-w flag) and fatal errors (-e flag). For debugging  purposes,
71       the  -d  flag  will cause g.message to print a debugging message at the
72       given level.
73

NOTES

75       Messages containing "=" must use the full message= syntax so the parser
76       doesn’t get confused.
77
78       If  you  want  a long message (multi-line) to be dealt with as a single
79       paragraph, use a single call to g.message with text split in the script
80       using  the  backslash  as  the  last character. (In shell scripts don’t
81       close the "quote")
82
83       A blank line may be obtained with
84       g.message message=""
85
86       Redundant whitespace will be stripped away.
87
88       It’s advisable to single quote the messages that are to be printed lit‐
89       erally.   It  prevents  a number of characters (most notably, space and
90       the dollar sign ’$’) from being treated specifically by the shell.
91
92       When it is necessary to include, for example,  a  variable’s  value  as
93       part  of  the  message, the double quotes may be used, which do not de‐
94       prive the dollar sign of its special variable-expansion powers.
95
96       While it is known that the interactive Bash instances may treat the ex‐
97       clamation  mark ’!’ character specifically (making single quoting of it
98       necessary), it shouldn’t be the case for the non-interactive  instances
99       of Bash. Nonetheless, to avoid context-based confusion later on you are
100       encouraged to single-quote messages that do not require  $VARIABLE  ex‐
101       pansion.
102
103   Usage in Python scripts
104       GRASS Python Scripting Library defines special wrappers for g.message.
105
106           •   debug() for g.message -d
107
108           •   error() for g.message -e
109
110           •   fatal() for g.message -e + exit()
111
112           •   info() for g.message -i
113
114           •   message() for g.message
115
116           •   verbose() for g.message -v
117
118           •   warning() for g.message -w
119
120       Note:  The Python tab in the wxGUI can be used for entering the follow‐
121       ing sample code:
122
123       import grass.script as gcore
124       gcore.warning("This is a warning")
125       is identical with
126       g.message -w message="This is a warning"
127
128   VERBOSITY LEVELS
129       Controlled by the "GRASS_VERBOSE" environment variable. Typically  this
130       is set using the --quiet or --verbose command line options.
131
132           •   0 - only errors and warnings are printed
133
134           •   1 - progress messages are printed
135
136           •   2 - all module messages are printed
137
138           •   3 - additional verbose messages are printed
139
140   DEBUG LEVELS
141       Controlled by the "DEBUG" GRASS gisenv variable (set with g.gisenv).
142       Recommended levels:
143
144           •   1 - message is printed once or few times per module
145
146           •   3 - each row (raster) or line (vector)
147
148           •   5 - each cell (raster) or point (vector)
149

EXAMPLES

151       This basic example prints the message "hello" in the console:
152       g.message message="hello"
153
154       To print a message as an error message use the -e flag:
155       g.message -e message="my error"
156
157       To  print  a  message highlighted as a debug message ("D0/0: debug") in
158       the console, use the -d flag. Optionally the debug level can be defined
159       (see also g.gisenv for details):
160       # Levels: (recommended levels)
161       #   0 - silence
162       #   1 - message is printed once or few times per module
163       #   3 - each row (raster) or line (vector)
164       #   5 - each cell (raster) or point (vector)
165       g.message -d message="debug" debug=0
166
167       To print a message highlighted as a warning message ("WARNING: my warn‐
168       ing") in the console, use the -w flag:
169       g.message -w message="my warning"
170

SEE ALSO

172        GRASS variables and environment variables
173       g.gisenv, g.parser
174

AUTHOR

176       Jachym Cepicky
177

SOURCE CODE

179       Available at: g.message source code (history)
180
181       Accessed: Saturday Oct 28 18:17:20 2023
182
183       Main index | General index | Topics index | Keywords index |  Graphical
184       index | Full index
185
186       © 2003-2023 GRASS Development Team, GRASS GIS 8.3.1 Reference Manual
187
188
189
190GRASS 8.3.1                                                       g.message(1)
Impressum