In Example 2, the result is still that
i
equals 1, but now
j
equals 9, because
i
is incremented
to 1 before the expression is evaluated (10 – 1 = 9).
Similarly, you can use the decrement operator (– –) to decrement local variables.
Placement of the operator has the same effect as for the increment operator.
When a local variable with a string value is used with the increment or decrement
operators, the value is permanently converted to an integer equal to the length in
characters of the string value.
String Operations
The combine operator ($) concatenates two strings into one longer string. Numeric
expressions are converted to strings before the operation proceeds. The variable
local
evaluates to “ want a big” :
Example
\<# local := “ want a ” $ “ big” #>
Extraction Operations
The extraction operations are substring (substr), randomize (rand), round, and truncate.
These operators are equal in precedence, and all take precedence over the string operator.
You can use the substring operator (substr) to extract a shorter string from a longer
string. To use the substring operator, you must specify the source string, an offset value,
and a count value. You can specify the string directly, or you can specify a local variable
that contains the string. The offset value indicates the place of the first character of the
substring to be extracted; “ 0” indicates the first character in the source string. The count
value indicates the length of the substring. If the source string has fewer characters than
the sum of the offset and count values, then the resulting substring has fewer characters
than indicated by the count value.
Example
<# local := “ want a ” $ “ big” $ “ string” #>
<# substr(local, 5, 12) #>The result is “ a big string”
<# substr(local, 0, 10) #>The result is “ want a big”
<# substr(“ ready” , 0, 4) #>The result is “ read”
The random operator produces a random integer value from the specified inclusive range;
in the following example, the result is between 1 and 10:
<# number:= rand(1,10) #>
The round operator rounds off the number to the nearest integer:
<# decimal:= 4.7 #>
<# round(decimal) #>The result is decimal is now 5
The truncate operator truncates noninteger numbers to the value left of the decimal
point:
<# decimal:= 4.7 #>
<# truncate(decimal) #>The result is decimal is now 4
469
Copyright © 2010, Juniper Networks, Inc.
Chapter 8: Writing CLI Macros
Summary of Contents for JUNOSE 11.3
Page 6: ...Copyright 2010 Juniper Networks Inc vi...
Page 8: ...Copyright 2010 Juniper Networks Inc viii JunosE 11 3 x System Basics Configuration Guide...
Page 24: ...Copyright 2010 Juniper Networks Inc xxiv JunosE 11 3 x System Basics Configuration Guide...
Page 32: ...Copyright 2010 Juniper Networks Inc 2 JunosE 11 3 x System Basics Configuration Guide...
Page 146: ...Copyright 2010 Juniper Networks Inc 116 JunosE 11 3 x System Basics Configuration Guide...
Page 166: ...Copyright 2010 Juniper Networks Inc 136 JunosE 11 3 x System Basics Configuration Guide...
Page 432: ...Copyright 2010 Juniper Networks Inc 402 JunosE 11 3 x System Basics Configuration Guide...
Page 488: ...Copyright 2010 Juniper Networks Inc 458 JunosE 11 3 x System Basics Configuration Guide...
Page 524: ...Copyright 2010 Juniper Networks Inc 494 JunosE 11 3 x System Basics Configuration Guide...
Page 554: ...Copyright 2010 Juniper Networks Inc 524 JunosE 11 3 x System Basics Configuration Guide...
Page 566: ...Copyright 2010 Juniper Networks Inc 536 JunosE 11 3 x System Basics Configuration Guide...
Page 588: ...Copyright 2010 Juniper Networks Inc 558 JunosE 11 3 x System Basics Configuration Guide...
Page 613: ...PART 3 Index Index on page 585 583 Copyright 2010 Juniper Networks Inc...
Page 614: ...Copyright 2010 Juniper Networks Inc 584 JunosE 11 3 x System Basics Configuration Guide...
Page 632: ...Copyright 2010 Juniper Networks Inc 602 JunosE 11 3 x System Basics Configuration Guide...