Passing Parameters In Macros - Juniper SYSTEM BASICS - CONFIGURATION GUIDE V 11.1.X Configuration Manual

System basics configuration guide software for e series broadband services routers
Table of Contents

Advertisement

JUNOSe 11.1.x System Basics Configuration Guide
expression skips over the rest of the expression group, evaluates any iteration
expression, then continues with the execution of the while structure. The while
structure is limited to 100,000 repetitions by default. You can nest up to 10 while
structures.
The following sample macro demonstrates various while structures:
Example
<#
<# //---------------------------------------- #>
<# // Remember that variables are automatically initialized to 0. #>
! Table of squares of the first 10 integers:
<# while ++i <= 10 #>
!<#i;"
<# endwhile #>
<# // Remember that the value of a string used as an integer is the number. #>
<# // of characters in the string.
<# stars := "*" #>
<# while stars < 10, stars := stars $ "*"#>
!<# stars;"\n" #>
<# endwhile #>
<# while stars > 0, stars := substr(stars, 0, stars-1)#>
!<# stars;"\n" #>
<# endwhile #>
<# // An example of the continue and break statements. #>
<# // Also note that many statements can be grouped. #>
! All the positive even numbers less than 11
<# i:=0; while ++i < 100 #>
<#if i%2; continue; endif; if i > 10; break; endif; "!" $ i $ "\n"; #>
<# endwhile #>
<# // While constructs will NOT iterate forever. #>
<# while 100 > 0 // This is always true, but the macro will eventually stop #>
<# ++iterations; endwhile #>
! The while loop iterated <#iterations#> times.
<# endtmpl #>

Passing Parameters in Macros

You can pass parameters to an entry macro. The system translates these parameters
to the correct data type.
NOTE: The env.argv array is separate from this feature and still functions as designed.
In other words, the env.argv array continues to pass parameters as text strings. To
use env.argv array values for subsequent numeric operations, you must first convert
the values to a number by using the env.atoi(string) command.
The following macro (saved as m.mac) uses values specified in a CLI command to
Example
compute the final result:
488
Writing Macros
while_examples
";i*i;"\n"#>
<# m(left,right,third) #>
<# multi := left * right #>
<# multiFinal := multi * third #>
<# setoutput console #>
<# " The result is: multiFinal; " \n" #>
<# endsetoutput #>
<# endtmpl #>
#>
#>

Advertisement

Table of Contents
loading

This manual is also suitable for:

Junose 11.1

Table of Contents