Please enable JavaScript to view this site.

A-Shell Reference

Navigation: System Commands

IF, ELSE, ENDIF

Scroll Prev Top Next More

Updated May 2026; see History

IF <expr>

   <statement(s) to execute if true>

ELSE

   <statement(s) to execute if false>

ENDIF

IF, ELSE and ENDIF allow for the flow of control within a CMD or DO file based on various conditions that can be tested. IF takes an expression that evaluates to true or false, while ELSE and ENDIF take no arguments. See the example below and Command Files for more information.

Example

This DO file takes a filename argument, without extension. If the filename doesn't exist (with a BAS extension), it is created by copying from another file and then loaded into VUE. If no argument is supplied, or the file already exists, it prints an error message and exits. Note that the EXIT command exits entirely out of the CMD/DO file, regardless of the depth of IF/ENDIF nesting, unlike the ASB EXIT control statement.

IF "$0" = ""

    :<This command needs a filename argument>

    EXIT                      ; exit DO file

ELSE

    IF LOOKUP("$0.BAS") = 0   ; if file does not exist

        COPY $0.BAS=APPLIB:STDHDR.TXT

    ELSE

        :<$0.BAS already exists; command aborted>

        EXIT                  ; exit DO file

    ENDIF

ENDIF

VUE $0.BAS

 

History

2026 May, A-Shell 1786:  Update IF.LIT (x.x.xxx) and ECHO.LIT (x.x.xxx) to support a new variable ($?) that equates to the exit status of the last module execution. For example:

RUN PROG1

ECHO PROG1 Exit Status: $?

IF $? <> 0 

    ECHO Error, cannot continue

    GOTO ENDIT

ELSE

    RUN PROG2

ENDIF

;ENDIT

 

Note that this variable is not recognized by DO.LIT.