Shell Commands/Else

From MorphOS Library

< Shell Commands

Else - Specifies an alternative for an IF statement in a script file.

No Template

Else must be used in conjunction with the If command. Else is used in an If block of a script to specify an alternative action if the If condition is not true. If the If condition is not true, execution of the script jumps from the If line to the line after Else; all intervening commands are skipped. If the If condition is true, the commands immediately following the If statement are executed up to the Else. Then, execution skips to the EndIf statement that concludes the IF block.

Example: Assume a script, called Display, contains the following block:

IF exists picfile
    MultiView picfile
    ECHO "picfile is not in this directory"

If picfile can be found in the current directory, the MultiView program is executed and picfile is displayed on the screen. If picfile cannot be found in the current directory, the script skips to the ECHO command. The following message is displayed in the Shell window: 'picfile is not in this directory'