Environment variables are used in scripts to hold status and string information. Variables can be substituted for strings that are long and tedious to enter. Changing the value of the variable is more convenient that re-editing the script when the value for the string changes.
Environment variables are maintained by AmigaDOS rather than individual applications. These variables can be accessed and used by different programs or scripts. When a variable name preceded by a dollar sign ($) is encountered in a script, the variable name is replaced by the value assigned to the variable. The line is then executed as if you had originally entered the value.
For example, AmigaDOS maintains the variables Workbench and Kickstart that track the current version numbers of your Workbench and Kickstart software. Running the following line prints the Workbench version number.
ECHO "Amiga Workbench Disk. Release Version $Workbench"
Some variables, such as the Workbench and Kickstart variables, have already been created. The Shell responds to the ECHO variable and maintains the PROCESS, RC, and RESULT2 local variables automatically. These are explained as follows:
For example, if you include the SET ECHO ON command at the beginning of a script, each line of the script is echoed to the screen as it is executed.
When an environment variable is given a numeric value, it can be used in calculations and expressions. For example, if you assign the value 9 to a variable called nine, $nine in EVAL expressions. For example:
1> SETENV nine 9
1> EVAL 5 * $nine
45
EVAL is an AmigaDOS command that evaluates integer and Boolean expressions. However, it does not work on environment variables that have a fractional numeric value; be sure to use whole numbers when using EVAL.
Environment variables can be created with the SET and SETENV commands.
SET creates local variables, which are recognized only by the Shell in which they are created and any Shells created by that original Shell. For example, if you are creating an environment variable in your Shell window, then execute the NEWSHELL command through the Execute Command menu item, the new Shell does not recognize any of the variables created in your original Shell. However, if you open a second Shell by entering the NEWSHELL command in your original Shell, the new Shell recognizes any variables created in its parent Shell.
Using the GET command displays the value associated with a variable; using the UNSET command removes variables.
SETENV creates global variables recognized by all Shells. Global variables are stored as small ASCII files in the ENV: directory. GETENV displays the value associated with global variables and UNSETENV removes global variables. Use global variables only when certain values must be available to other processes.
Some applications use environment variables. For example, the MORE program supports an Editor environment variable. You can use SETENV to specify MEmacs as your editor of choice:
1> SETENV Editor Extras:Tools/MEmacs
Be sure to specify the complete path to MEmacs.
If you use MORE to view the contents of the User-startup file, pressing Shift+E automatically transfers to a MEmacs screen with the User-startup loaded and ready for editing.