Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This could be accomplished by two well-phrased if statements, one following the other, as in this example:

<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>
Panel
Html bobswift


Flaws in this Methodology

...

  1. 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.
  2. 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:

html-bobswift
Panel
<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:

<pre>
if expression
...
[else
...
end
</pre>
Panel
Html bobswift


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

html-bobswift
Panel
<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
titleNote

The previous style of UDM if statements, shown in the following example, still is valid:


Panel

...

...

if <$(_lastrc) GE 8>
  print msg="The last command was not successful"
else
  print msg="The last command was successful"
end

...