[erlang-questions] bug in escript and a question
Håkan Mattsson
hm@REDACTED
Tue Oct 5 15:50:42 CEST 2010
> On Tue, Oct 5, 2010 at 1:39 PM, Lars Thorsen <lars@REDACTED> wrote:
>>
>> You can't have Erlang code on the first line in an escript, here are some
>> lines from the man page ;).
>>
>> --------------------------------
>> The header of the Erlang script in the example differs from a normal Erlang
>> module. The first line is intended to be the interpreter line, which invokes
>> escript. However if you invoke the escript like this
>>
>> $ escript factorial 5
>>
>> the contents of the first line does not matter, but it cannot contain Erlang
>> code as it will be ignored.
>
> Goodness gracious me - you are indeed correct -
>
> My flabber has been gasted - this surely violates the principle of
> least astonishment, I need a nip of strong smelling-salts to recover.
>
> I thing it would be splendiferous if one could add a line of code in
> the first line of an escript file and if the documentation were to be
> revised to remove this rather bizaare restriction.
The "normal" way of writing escripts is to have "#!/usr/bin/env escript"
as the first line. But if you find it bizarre, you may have the source code
of a complete Erlang module (with the module attribute and export of
main/1) in the escript file. The drawback of this is however that you
cannot invoke the script with just its name (factorial 5) as you must
invoke escript with your script name as argument (escript factorial 5).
/Håkan
More information about the erlang-questions
mailing list