The erlangrc file

There could be an erlang resource file named as “.erlang” in your working
directory or home directory. This file is loaded and evaled when erlang is
started. So you can do some initialization in this file.

Let’s look into start_clean.script and start_sasl.script.

%% the next line is only present in start_sasl.script

After kernel, stdlib and sasl is started, c:erlangrc/0 will be called.

%% erlangrc(Home)
%%  Try to run a ".erlang" file, first in the current directory
%%  else in home directory.

erlangrc() ->
    case init:get_argument(home) of
    {ok,[[Home]]} ->
    _ ->
        f_p_e(["."], ".erlang")

erlangrc([Home]) ->
    f_p_e([".",Home], ".erlang").

f_p_e(P, F) ->
    case file:path_eval(P, F) of
    {error, enoent} = Enoent ->
    {error, E={Line, _Mod, _Term}} ->
        error("file:path_eval(~p,~p): error on line ~p: ~s~n",
          [P, F, Line, file:format_error(E)]),
    {error, E} ->
        error("file:path_eval(~p,~p): ~s~n",
          [P, F, file:format_error(E)]),
    Other ->

Something we should know about file:path_eval:

path_eval(Path, Filename) -> {ok, FullName} | {error, Reason}

Searches the path Path (a list of directory names) until the file
Filename is found. If Filename is an absolute file name, Path is
ignored. Then reads and evaluates Erlang expressions, separated
by ’.’ (or ’,’, a sequence of expressions is also an expression),
from the file. The actual result of evaluation is not returned; any
expression sequence in the file must be there for its side effect.
Returns one of the following:

c:erlangrc/0 is wrapped in shell_default, so you can type erlangrc([“.”]).
in the erlang shell to reload your .erlang file at any time.

This entry was posted in erlang and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s