escript

    A simple one pass "load and go" Erlang scripting interface

    Joe Armstrong
    Robert Virding

    3 - April - 2001

    Installation

    1. Fetch escript-3.0.tgz
    2. Unpack.
    3. Type make.
    4. Move the file escript to somewhere in your path.

    Testing

      
      > ./factorial abc
      Usage factorial <Int>  
      > ./factorial 100
      factorial 100 = 9332621544394415268169923885626670049071596826438162146859
      29638952175999932299156089414639761565182862536979208272237582511852109168
      64000000000000000000000000          
      
      
    The factorial script is as follows:
      
      #!/usr/bin/env escript 
      
      %%
      %%
      %% Usage:
      %%   factorial 
      
      main([X]) ->
          case (catch list_to_integer(X)) of
      	{'EXIT', _} ->
      	    usage();
      	J ->
      	    N = fac(J),
      	    io:format("factorial ~w = ~w~n",[J, N])
      	end;
      main(_) ->
          usage().
      
      usage() ->
          io:format("Usage factorial ~n").
      
      fac(0) -> 1;
      fac(N) ->
          N * fac(N-1).
      
      

    Compiled or Interpreted code?

    The default mode of escript is to interpret the code. By adding the attribute:

      
      -mode(compile).
      

    Will cause the code in the script to be compiled, instead of interpreted. Note that for many scripts interpreting the code is much faster than compiling the code.

    Release Notes

    This version of escript uses a (slightly) hacked version of erl_eval.erl. The version of erl_eval.erl included here should be placed in your path in front of the "official" version of erl_eval. Hopefully the version of erl_eval and escript included here will find their way into the the official distribution.

    Bugs

    • 8 years too late :-)
    • Imports, exports macros and includes are not understood.
    • The escaping in the the escript script works in bash - but maybe not in sh.

    Versions

    • escript-2.0 Added suggestion by Luke Gorrie on quoting arguments. Added -mode(compile).
    • escript-3.0 Added Fix by Bengt Kleberg (should be #! /bin/sh not #!/bin/sh).