Manually abort a script

If you wish to manually stop a running script (ie, tell REXX to abort), press the Control (Ctrl) and C keys simultaneously. That is, press and hold down the Ctrl key and then press the C key once. (Some REXX interpreters use the Break key instead of the C key).

Note: Pressing Ctrl and C will raise a HALT condition (discussed later) in the script. If the script traps the HALT condition, then the script may not abort.

Note: If using Rexx Dialog to create a graphical user interface, then CTRL-C does not raise the HALT condition, nor terminate a REXX script. If running a script from the RexxEd text editor, then you can simply use the "Halt script" menu item to raise the HALT condition.


EXIT keyword

A script can stop itself by executing the EXIT instruction, which consists simply of the EXIT keyword. As soon as REXX encounters an EXIT instruction, it ends the script, regardless of whether there are more instructions after the EXIT.

/* Terminate the script before the last line */
SAY "Here is some text"
EXIT
SAY "More text"
Above, the script displays Here is some text, but the script ends before the second SAY instruction, and therefore More text never gets displayed.

An EXIT is implicitly understood to be at the bottom of a script. In other words, when REXX gets to the last line in a script, it automatically ends the script after that last instruction (unless that instruction causes a jump back to some earlier instruction in the script such as may be the case with the END or SIGNAL keywords). So, you don't need an EXIT instruction at the bottom of a script, although it's OK to put one there.

You can have more than one EXIT instruction in a script, if you need to end the script in various places.

NOTE: If using Rexx Dialog to create a graphical user interface, then, prior to any EXIT, you should insert a call to RXMSG() with an END Operation, as described in Terminating a REXX Dialog script.


Returning a value

If you wish to return a value to the program that ran your script (or if your script was launched by another REXX script, and you wish to return a value to be stored in that other REXX script's 'RC' variable), then simply place that value after the EXIT keyword. Typically, you return a 0 if the script has no errors. Here, we return an "error number" of 30.

EXIT 30
You can return a literal string if desired, for example here we return the string Some text:
EXIT "Some text"
You can also specify a variable name, and its value is substituted, for example here we return the value of the variable 'MyVar':
MyVar = "Some text"
EXIT MyVar
Sometimes, the program that runs your script may do something with the value you return. Check the documentation for the program you use to run your script, to see what sorts of values (if any) it understands/allows, and for what purpose it uses a value you return.

Note: Neither Reginald's Script Launcher, nor RexxEd, require you to return any value, and will not do anything with any value you return.