Home Page The Club Computers News Links Glossary EYAWTK
Before Amiga Background ICS OCS ECS AGA ??? PPC
U-Boot SLB Linux Amiga OS Dual Boot Motherboards Peripherals Other
Initialisation Installation OS4 Updates About OS4 File Systems Networking Printing Other
Introduction File System Workbench Preferences Commands Error Msgs Miscellaneous

AmigaOS 4.0 - About OS4 - Commands

EVAL AmigaDOS
Purpose: To evaluate simple expressions.
Format: EVAL <value1> [<operation>] [<value2>] [TO <file>] [LFORMAT <string>]
Template: VALUE1/A, OP, VALUE2, TO, LFORMAT/K
Path: C:EVAL
EVAL is used to evaluate and print the answer of an integer expression. The fractional portion of input values and final results, if any, is truncated (cut off).

<value1> and <value2> may be in 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 specification (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 in the table below:


OperationSymbol

addition+
subtraction-
multiplication*
division/
modulomod
AND&
OR|
NOT^
left shift<<
right shift>>
negation-
exclusive ORxor
bitwise equivalenceeqv
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:

3.OS4:> EVAL 4 * -5
-20
Example 2: 3.OS4:> EVAL 0x4f / 010 LFORMAT="The answer is %X4*N"
The answer is 0009
this divides hexadecimal 4f (79) by octal 10 (8), yielding 0009, the integer portion of the decimal answer 9.875. (The 3.OS4:>> prompt would have appeared immediately after the 0009 if *N had not been specified in the LFORMAT string.)

Example 3:

Assume you were using the following script, called Loop:

.Key loop/a
; demonstrate a loop using eval and skip
.Bra {
.Ket }
ECHO >ENV:Loop {loop}
LAB start
ECHO "Loop #" noline
TYPE ENV:Loop
EVAL <ENV:Loop >NIL: to=T:Qwe{$$} value2=1 op=- ?
TYPE >ENV:Loop T:Qwe{$$}
IF val $loop GT 0
SKIP start back
ENDIF
ECHO "done"
If you were to type: 3.OS4:> EXECUTE Loop 5 The following results would be displayed: 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>. <value2> is 1, and the operation is subtraction. The output of the EVAL command is sent to the T:Qwe($$) file. In this case, the value would be 4.

The next TYPE 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.

See also: ECHO, EXECUTE, IF, TYPE,


Return to Commands Selection

Disclaimer: Amiga Auckland have prepared the above information for the use of its members based on our experiences and as such is subject to revision at any time. Amiga Auckland cannot guarantee any of the information and cannot be held accountable for any issues that may result from using it.


Copyright 2006 Amiga Auckland Inc. All rights reserved.
Revised: February 9, 2006.