...
This could be accomplished by two well-phrased if statements, one following the other, as in this example:
Panel |
---|
Html bobswift |
---|
<pre>
if <$(_rc) GE 8>
echo "There has been an error"
end
if <$(_rc) LT 8>
echo "There has not been an error"
end
</pre>
|
|
Flaws in this Methodology
...
- You may find such logic difficult to read, thus making your UDM scripts more difficult to maintain, especially if you did not write them in the first place.
- If the comparison operation contains a variable and evaluates to true for the first comparison, it is possible something occurs in the statements inside the if-end pair that changes the value of the variable and makes the second comparison evaluate to true as well.
For example:
Panel |
---|
Html bobswift |
---|
<pre>
if <$(_lastrc) GE 8>
echo "The last command was not successful"
end
if <$(_lastrc) LT 8>
echo "The last command was successful"
end
</pre>
|
|
In this example, if the command executed before the first if statement resulted in an error, the output would have been as follows:
...
The general format of an if statement when an else statement is used with it is:
Panel |
---|
Html bobswift |
---|
<pre>
if expression
...
[else
...
end
</pre>
|
|
In this if statement, the parameter for the statement is an expression. If the expression evaluates to a value that is not equal to zero, the positive branch is taken; otherwise the negative (else) branch is taken if one exists.
Examples
Panel |
---|
Html bobswift |
---|
<pre>
if <$(_rc) EQ 0>
echo "Everything worked okay"
else
echo "Something went wrong"
end
if <"$(myvar.exists)" EQ "yes">
echo "The variable, myvar, has been defined."*
end
</pre>
|
|
Note |
---|
|
The previous style of UDM if statements, shown in the following example, still is valid: |
Panel |
---|
Html bobswift |
---|
<pre>
if <$(_lastrc) GE 8>
print msg="The last command was not successful"
else
print msg="The last command was successful"
end
</pre>
|
|