[AmigaOS 3.1 Command Reference/Eval] 
 

EVAL

Format: EVAL <value1> {[<operation>] [<value2>]} [TO<file>] [LFORMAT=<string>] Template: VALUE1/A, OP, VALUE2/M, TO/K, LFORMAT/K Purpose: To evaluate simple expressions. Path: C:EVAL Specification: EVAL is used to evaluate and print the answer of an integer expression. The fractional portion of input values and final results, if any, are truncated (cut off). Decimals are not allowed, evaluation stops at the decimal point. <Value1> and <value2> may be decimal, hexadecimal, or octal numbers. Decimal numbers are the default. Hexadecimal numbers are indicated by either a leading 0x or #x. Octal numbers are indicated by either a leading 0 or a leading #. Alphabetical characters are indicated by a leading single quote ('). The output format defaults to decimal; however, you can use the LFORMAT keyword to select another format. The LFORMAT keyword specifies the formatting string used to print the answer. You may use %X (hexadecimal), %O (octal), %N (decimal), or %C (character). The %X and %O options require a number of digits specifcation (i.e., %X8 gives 8 digits of hex output). When using the LFORMAT keyword, you can specify that a new line should be printed by including a *N in your string. The supported operations and their corresponding symbols are shown below: Operation Symbol --------- ------ addition + subtraction - multiplication * division / modulo mod AND & OR | NOT ~ left shift lsh right shift rsh negation - exclusive OR xor bitwise equivalence eqv EVAL can be used in scripts to act as a counter for loops. In that case, the TO option, which sends the output of EVAL to a file, is very useful. Parentheses may be used in the expressions. Example 1: 1> EVAL 64 / 8 + 2 10 Example 2: 1> EVAL 0x5f / 010 LFORMAT="The answer is %X4*N" The answer is 000B This divides hexadecimal 5f(95) by octal 10(8), yielding 000B, the integer portion of the decimal answer 11.875. (The 1> prompt would have appeared immediately after the 000B if *N had not been specified in the LFORMAT string.) Example 3: Assume you were using the following script, called Loop: Key loop/a .Bra { .Ket } ECHO >ENV:Loop {loop} LAB start ECHO "Loop #" noline TYPE ENV:Loop EVAL <ENV:Loop >NlL: to=T:Qwe{$$} value2=1 op=- ? TYPE >ENV:Loop T:Qwe{$$} IF val $loop GT 0 SKIP start back ENDIF DELETE ENV:Loop T:Qwe{$$} ; clean up ECHO "done" If you were to enter: 1> EXECUTE Loop 5 The following results would be displayed: 1> EXECUTE Loop 5 Loop #5 Loop #4 Loop #3 Loop #2 Loop #1 done The first ECHO command sends the number given as the loop argument, entered as an argument of the EXECUTE command, to the ENV:Loop file. The second ECHO command coupled with the TYPE command, displays Loop # followed by the number given as the loop argument. In this case, it displays Loop #5. The EVAL command takes the number in the ENV:Loop file as <value1>, which makes the question mark at the end of the line necessary. <Value2> is 1, and the operation is subtraction. The output of the EVAL command is sent to the T:Qwe{$$} case, the value would be 4. The next IF command sends the value in the T:Qwe{$$} file to the ENV:Loop file. In this case, it changes the value in ENV:Loop from 5 to 4. The IF statement states that as long as the value for Loop is greater than 0, the script should start over. This results in the next line being Loop #4. The script will continue until Loop is equal to 0.


Converted from AmigaGuide to HTML by Jaruzel