63
64
the contents of the first line does not matter, but it cannot contain Erlang code as it will be \fIignored\fR\&.
66
The second line in the example, contains an optional directive to the \fIEmacs\fR editor which causes it to enter the major mode for editing Erlang source files\&. If the directive is present it must be located on the second line\&.
68
On the third line (or second line depending on the presence of the Emacs directive), it is possible to give arguments to the emulator, such as
71
%%! -smp enable -sname factorial -mnesia debug verbose
74
Such an argument line must start with \fI%%!\fR and the rest of the line will interpreted as arguments to the emulator\&.
65
76
If you know the location of the \fIescript\fR executable, the first line can directly give the path to \fIescript\fR\&. For instance:
68
#!/usr/local/bin/escript factorial
71
As any other kind of scripts, Erlang scripts will not work on Unix platforms if they execution bit for the script file is not set\&. (Use \fIchmod +x script-name\fR to turn on the execution bit\&.)
82
As any other kind of scripts, Erlang scripts will not work on Unix platforms if the execution bit for the script file is not set\&. (Use \fIchmod +x script-name\fR to turn on the execution bit\&.)
73
84
An Erlang script file must always contain the function \fImain/1\fR\&. When the script is run, the \fImain/1\fR will be called with a list of strings representing the arguments given to the script (not changed or interpreted in any way)\&.
75
86
Call \fIescript:script_name/0\fR from your to script to retrieve the pathname of the script (the pathname is usually, but not always, absolute)\&.
77
It is not necessary to export the \fImain/1\fR function\&.
79
88
By default, the script will be interpreted\&. You can force it to be compiled by including the following line somewhere in the script file:
94
It is not necessary to export the \fImain/1\fR function when the script is interpreted or dynamically compiled\&.
96
It is also possible to have a precompiled script which contains a \fIbeam\fR file\&. In a precompiled script, the interpretation of the script header is exactly the same as in a script containing source code\&. That means that you can make a \fIbeam\fR file executable by prepending the file with the lines starting with \fI#!\fR and \fI%%!\fR mentioned above\&. In a precompiled script, the function \fImain/1\fR must be exported\&.
98
As yet another option it is possible to have an entire Erlang archive in the script\&. In a archive script, the interpretation of the script header is exactly the same as in a script containing source code\&. That means that you can make an archive file executable by prepending the file with the lines starting with \fI#!\fR and \fI%%!\fR mentioned above\&. In an archive script, the function \fImain/1\fR must be exported\&. By default the \fImain/1\fR function in the module with the same name as the basename of the \fIescript\fR file will be invoked\&. This behavior can be overridden by setting the flag \fI-escript main Module\fR as one of the emulator flags\&. The \fIModule\fR must be the name of a module which has an exported \fImain/1\fR function\&. See code(3erl) for more information about archives and code loading\&.
101
The support for loading of code from archive files is experimental\&. The sole purpose of releasing it before it is ready is to obtain early feedback\&. The file format, semantics, interfaces etc\&. may be changed in a future release\&. The flag \fI-escript\fR is also experimental\&.
85
104
Pre-processor directives in the script files are ignored, with the exception for the \fI-include_lib\fR directive\&. For instance, use