Tools: MPW
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Support

MPW Command Reference


Evaluate

Built-in

SYNTAX

Evaluate (operand operator operand)… [-b | -h | -H | -o]
Evaluate name [operator]= operand

DESCRIPTION

The Evaluate command evaluates an expression given in one of the above syntax forms and either returns a value or defines a variable. The first syntax form allows you to specify a string of any number of operand-operator-operand sequences, such as (30+6) ÷ (9-3). In this case, Evaluate returns the value of the expression (6).

The second syntax form defines a variable (name) to a value, using C language operators such as += and -=. If the variable does not already exist, it is interpreted as 0 before being modified according to the operator and operand. In this case, Evaluate does not return a value; instead it defines a variable. If it does exist, its value is modified according to the operator and operand.

INPUT

None

OUTPUT

Standard output. The Evaluate command returns a value to standard output when used with the first syntax form. Expressions containing logical operators (such as &&, >, and !-) return the values 0 (false) and 1 (true).

Expressions containing mathematical operators evaluate to their actual value. By default, Evaluate returns decimal numbers but you can request either binary, hexadecimal, or octal numbers instead (-b, -h, -H, -o).

Note
To redirect standard output or diagnostic output, enclose the Evaluate command in parentheses; otherwise, Evaluate erroneously interprets the > and symbols as expression operators. •

STATUS

Evaluate can return the following status codes:

0

valid expression

1

invalid expression

PARAMETERS

Note that all null parameters evaluate to 0.

name

Specifies a variable whose value is set or modified.

operand

Specifies the numerical or string data on which the operator works. Most operators require numerical operands, specified as either decimal, binary, hexadecimal, or octal values. These numerical types and their radices follow:

Decimal

[0-9]

Binary

0b[01]

Hexadecimal

0x[0-9A-F]  or  $[0-9A-F]

Octal

0[0-7]

Note the prefixes 0b for binary, 0x or $ for hexadecimal, and 0 for octal.

String variables can be used with the ==, !=, =~, and !~ operators. The latter two operators require that the operands on the right be regular expressions.

operator

Specifies a symbol, such as +, &&, or !, that works on the operands. See Appendix C for a complete list of operators and their definitions.

OPTIONS

-b

Writes the result as a binary number, prefixing it with 0b.

-h

Writes the result as a hexadecimal number, prefixing it with 0x.

-H

Writes the result as a hexadecimal number, prefixing it with 0x and using uppercase letters A-F.

-o

Writes the result as an octal number, prefixing it with 0.

EXAMPLES

Using the first syntax form, the command line

Evaluate (1+2) * (3+4)

computes the expression and writes the result to standard output:

21

The following command line computes the expression and writes the result to standard output as a hexadecimal number.

Evaluate 8 + 8 -h
0x10

The previous example specifies hexadecimal output, yet the operands used in the expression are decimal. The following command line, on the other hand, uses both a hexadecimal and a decimal number as operands and writes a decimal value (the default) to standard output.

Evaluate 0xA + 6
16

Using the second syntax form, the following command line increments the value of the MPW Shell variable {lines} by 1. If {lines} is an undefined variable, Evaluate sets its value to 1.

Evaluate lines += 1

In the following example, the =~ string operator (reserved for regular expressions) is used to return the directory prefix of the pathname contained in the variable {aPathname}. The right operand (/(([¬:]+:)*)®1≈/) is a regular expression that matches everything in the pathname up to the last colon and stores it as the MPW Shell variable {®1}. The Echo command then returns the directory prefix, {®1}.

(Evaluate "{aPathname}" =~ /(([¬:]+:)*)®1≈/) > Dev:Null
Echo {®1}

Since the actual output is unnecessary, it is redirected to the null device, Dev:Null. Note that the use of I/O redirection requires that the Evaluate command be enclosed in parentheses so that the output redirection symbol, >, is not taken as an expression operator.

LIMITATIONS

The Evaluate command does not allow filename generation, conditional execution, pipe specifications, or input/output redirection within expressions. To use these features outside expressions, you must place the entire Evaluate command line within parentheses.

SEE ALSO

If…

Break

Continue

Exit

 
 


Last Updated July 2000