[erlang-questions] shell question - import commands from external file
Tue Sep 22 21:14:33 CEST 2009
> I have a newbie question. In the shell, is there a way to
> import *shell* commands from an external file?
It's possible to add user-defined functions to the shell (which
can be called without the module name prefix). Just create a
module called user_default.erl and make sure it's compiled and in
in the code path. Here's a description from the shell  man
If a command (local function call) is not recognized by the
shell, an attempt is first made to find the function in the
module user_default, where customized local commands can be
placed. If found, then the function is evaluated. Otherwise,
an attempt is made to evaluate the function in the module
shell_default. The module user_default must be explicitly
Here's a really short example:
1. Create user_default.erl:
foo() -> foo.
2. Compile it.
3. erl -pa <path-to-user-default>
4. 1> foo().
You will have to recompile and reload the file if you change it
You can make sure the module is automatically loaded by adding it
to your ~/.erlang file as described in the man page for
shell_default  (then you wouldn't need the "-pa" option to erl):
To add your own commands to the shell, create a module called
user_default and add the commands you want. Then add the
following line as the first line in your .erlang file in your
Note: You should not change the shell_default module, since this
implements the existing shell functions, but instead add your own
functions to user_default.
I don't know if this will help you or not, since it doesn't solve
all of the problems you listed, but perhaps it can prove useful?
More information about the erlang-questions