REBOL Technologies

Quit/Return for Exit Codes

Carl Sassenrath, CTO
REBOL Technologies

Article #0005
Main page || Index || Prior Article [0004] || Next Article [0006] || 1 Comments || Send feedback

Now that redirection is fixed, it's time to add exit codes as well. In systems like Unix (Linux/BSD) exit codes allow REBOL programs to return their "exit status" to the command shell. This is a common practice in shells, and it is very useful if you want to combine your REBOL programs with other types of Unix commands and scripts. We've needed this for some time in REBOL, and quite frankly I'm surprised we ignored it for so long. (I've wanted this for my own Linux scripts for years.)

As an example, suppose you need a simple Linux shell script that executes a non-REBOL command (like a MAKE) depending on the results of a REBOL program. The shell script might look like this:

if (./rebol check-files.r) then
    make driver

If REBOL returns a "success" exit code, then the MAKE program will be executed. Otherwise, it will not.

In Unix-style shells, a success code is the integer value zero. Non-zero values are normally used to indicate errors or other types of events. To return an exit code from REBOL, use the QUIT function. The line:

quit/return 10

will return an exit code of 10. The /return refinement was picked because it is related to the BREAK form:

break/return value

Note that if your REBOL program just does a QUIT, or does no QUIT but simply exits off the bottom, a zero exit code (success) will be returned to the shell.

Alpha versions of REBOL that contain this function and the redirection changes below will be available for Linux and OpenBSD later today.


Updated 23-Nov-2017   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code