REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 22-May-2009 Edit History  

REBOL 3 Guide: Basics: Running scripts (programs)

There are several ways to run a script.


Run from an icon

On systems that support it (like Windows):

Run from a command shell (CLI)

From a shell prompt, go to the directory that contains the REBOL executable file and type:


or, on Windows command console, just:


You can include a script file name:

rebol build-web.r

And special scripts: program options can be provided:

rebol -u

Some operating systems such as UNIX let you create alias shell commands that are able to run REBOL with a set of arguments and files.

Run from the console

In the REBOL console, use do to run another script. For example:

do %build-site.r

Once that script has finished, it will return to the expression that follows it. If the script is in a different directory, REBOL will change to that directory while that script is run, and change back when done (if no errors occurred.)

Run from an editor

Usually, you can setup your favorite programming text editor to make code development go much quicker. Each text editor does this differently.

For instance, in some editors, you will use the language compiler options. Specify the REBOL program rather than a compiler. Then you can press a single key that saves the script and evaluates it.

See basics: editing scripts for more.

Run from embedded files

In Linux, BSD, and similar systems, you can embed REBOL scripts in other types of script files.

For example, if you created file list.r with these lines:

#!/path/to/rebol -s
REBOL [Title: "Example script"]
foreach file read %./ [print [file size? file]]

This works because REBOL ignores all text prior to its header object.

Now, from your OS shell (but not in MS Windows default shell), make test.r executable:

chmod +x test.r

and you can run it with:


Run from a web server as a CGI script

The above technique is also useful for CGI scripts used on web servers.

Here's an example CGI script:

#!/path/to/rebol -cs
REBOL [Title: "Example CGI script"]
print "Content-Type: text/html^/"
print [<html><body><pre> system/options </pre></body></html>]

The -cs indicates CGI and disable security (allow file access outside the sandbox).

When the web server runs this script, it will launch REBOL and provide the code that follows it as the script. Be sure to save the script with a file suffix (extension) that is supported by your web browser. (It may not support .r so you may need to use a .cgi suffix.)

Also note that you can run this file directly from REBOL, because it ignores all lines prior to the REBOL header.

Scripts need a header

In most cases REBOL requires that the script includes a REBOL header. This is a simple text signature at the top of the file that identifies the data as being REBOL code.

The line above is an example header:

REBOL [Title: "Example script"]

The error message will be:

** Syntax error: Script is missing a REBOL header.

See scripts: headers for more information.

  TOC < Back Next > - WIP Wiki Feedback Admin