The following example provides the output from using this macro:
host1#macro m.mac m 5 6 7
host1#The result is: 210
Generating Macro Output
You may want a macro to provide output while it is operating. In simple cases, you
can use the verbose keyword to echo commands to the display and display comments
as the macro executes. For more information about the verbose keyword, see
“Example 2” on page 483 in “Invoking Other Macros” on page 489.
When running more complex macros or macros that contain a lot of commands or
comments, you may want to output only certain information (that is, not all
commands and comments). In this case, you can use <# setoutput console #> to
send the information directly to the console display when it executes.
Example 1 The following example shows how you can send output directly to the console:
<# setoutput console #>
This message appears in the console window (whether or not you use verbose mode).
<#endsetoutput #>
Example 2 The following example shows how you can send a single argument to the console:
<# puts (msg) #>
!==================================================================
!==================================================================
! output "msg" to console
!==================================================================
!==================================================================
<# setoutput console #>
<# msg; "\n"#>
<#endsetoutput #>
<# endtmpl #>
!==================================================================
!==================================================================
<# tmpl.puts(“ Hello World” )
Invoking Other Macros
Macros can invoke other macros within the same macro file; a macro can also invoke
a macro from another macro file if the invocation takes place in literal text, that is,
not within a control expression. A macro can invoke itself directly or indirectly (an
invoked macro can invoke the macro that invoked it); the number of nested
invocations is limited to 10 to prevent infinite recursion.
Within each macro, you can specify parameters that must be passed to the macro
when it is invoked by another. You must specify named variables enclosed in
parentheses after the macro name in the first line of the macro, as shown in this
example:
<# macroName (count, total) #>
Writing Macros ■ 489
Chapter 8: Writing CLI Macros