UNIX for OpenVMS Users, Second Edition

Section 10.5: Comparison Operators

10.5 Comparison Operators

Table 10.4 illustrates the comparison operators supported by the C and Korn shells. We will encounter numerous uses of comparison operators in subsequent examples. We now introduce the if statement, discussed in greater detail under flow control in Section 10.8, to show how comparison operators function. The C shell uses the same operator for both text and integer variables, whereas both Korn shell and OpenVMS use a different comparison operator for each.

OpenVMS

Example:

$! Equal to$ IF (l .EQ. 10) THEN$ IF (STRING .EQS. "Red") THEN

Example:

$! Not equal to$ IF (l .NE. 10) THEN$ IF (STRING .NES. "Red") THEN

Example:

$! Greater than 1 and less than 10$ IF (l .GT. 1 .AND. l .LT. 10) THEN

Example:

$! Equal to 0 or 1$ IF (l .EQ. 0 .OR. l .EQ. 1) THEN

Example:

$! Equal to Blue OR Red$ IF (STRING .EQS. "Blue" .OR. STRING .EQS. "Red") THEN

Example:

$! Not less than or equal to 10$ IF (.NOT. (l .LE. 10)) THEN

Example:

$! A zero-length (null) string$ IF (F$LENGTH(STRING) .EQ. 0) THEN$ IF (STRING .EQS. "") THENUNIX (C shell)

Example:

# equal toif ($i == 10) thenif ($string == "Red") then

Example:

# not equal toif ($i != 10) thenif ($string != "Red") then

Example:

# greater than 1 and less than 10if ($i>1 && $i<10) then

Example:

# equal to 0 or 1if ($i == 0  $i == 1) then

Example:

# equal to Blue or Redif...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Color Meters and Appearance Instruments
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.