~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to debian/manpages/escript.1

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
.TH escript 1 "erts  5.6.3" "Ericsson AB" "USER COMMANDS"
 
1
.TH escript 1 "erts  5.6.5" "Ericsson AB" "USER COMMANDS"
2
2
.SH NAME
3
3
escript \- Erlang scripting support
4
4
.SH DESCRIPTION
24
24
 
25
25
#!/usr/bin/env escript
26
26
%% -*- erlang -*-
 
27
%%! -smp enable -sname factorial -mnesia debug verbose
27
28
main([String]) ->
28
29
    try
29
30
        N = list_to_integer(String),
62
63
.LP
63
64
the contents of the first line does not matter, but it cannot contain Erlang code as it will be \fIignored\fR\&.
64
65
.LP
 
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\&.
 
67
.LP
 
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 
 
69
 
 
70
.nf
 
71
%%! -smp enable -sname factorial -mnesia debug verbose
 
72
.fi
 
73
.LP
 
74
Such an argument line must start with \fI%%!\fR and the rest of the line will interpreted as arguments to the emulator\&.
 
75
.LP
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:
66
77
 
67
78
.nf
68
 
#!/usr/local/bin/escript factorial        
 
79
#!/usr/bin/escript        
69
80
.fi
70
81
.LP
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\&.) 
72
83
.LP
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)\&.
74
85
.LP
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)\&.
76
87
.LP
77
 
It is not necessary to export the \fImain/1\fR function\&.
78
 
.LP
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:
80
89
 
81
90
.nf
82
91
-mode(compile)\&.        
83
92
.fi
84
93
.LP
 
94
It is not necessary to export the \fImain/1\fR function when the script is interpreted or dynamically compiled\&.
 
95
.LP
 
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\&.
 
97
.LP
 
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\&.
 
99
.SS Warning:
 
100
.LP
 
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\&.
 
102
 
 
103
.LP
85
104
Pre-processor directives in the script files are ignored, with the exception for the \fI-include_lib\fR directive\&. For instance, use
86
105
 
87
106
.nf