www.delorie.com/gnu/docs/gforth/gforth_250.html   search  
 
Buy GNU books!


Gforth Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.7 Running Image Files

You can invoke Gforth with an image file image instead of the default `gforth.fi' with the -i flag (see section 2.1 Invoking Gforth):
 
gforth -i image

If your operating system supports starting scripts with a line of the form #! ..., you just have to type the image file name to start Gforth with this image file (note that the file extension .fi is just a convention). I.e., to run Gforth with the image file image, you can just type image instead of gforth -i image. This works because every .fi file starts with a line of this format:

 
#! /usr/local/bin/gforth-0.4.0 -i

The file and pathname for the Gforth engine specified on this line is the specific Gforth executable that it was built against; i.e. the value of the environment variable GFORTH at the time that `gforthmi' was executed.

You can make use of the same shell capability to make a Forth source file into an executable. For example, if you place this text in a file:

 
#! /usr/local/bin/gforth

." Hello, world" CR
bye

and then make the file executable (chmod +x in Unix), you can run it directly from the command line. The sequence #! is used in two ways; firstly, it is recognised as a "magic sequence" by the operating system(38) secondly it is treated as a comment character by Gforth. Because of the second usage, a space is required between #! and the path to the executable (moreover, some Unixes require the sequence #! /).

The disadvantage of this latter technique, compared with using `gforthmi', is that it is slightly slower; the Forth source code is compiled on-the-fly, each time the program is invoked.

doc-#!


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003