The erlang shell, erl, is a great tool while developing erlang code. Since I’m writing code in erlang sporadically I thought that writing a cheat sheet for the erl shell might help me to remember the basic commands better.
- help() - will display all of the available commands in the shell, which makes the list below pointless :-)
quit the shell
- q() - will call init:stop() internally, however be careful when using this since you will be shutting down the erlang runtime, not a good idea if you have connected to a remote shell.
- Ctrl-G and then q - use this when connected to a remote shell.
- h() - displays the latest 20 (default value) commands used in the shell.
- history(N) - sets the history length of the command above.
- results(N) - sets the history length of the results for previous commands.
- e(N) - executes command N again (the prompt in the shell is showing the current N for each command). Can be negative, e.g. e(-1), will execute previous command.
- v(N) - get the value from command N and use it in the current command. Can be negative, e.g. v(-1), will use the value from the previous command.
- ↑ - will navigate backward in the history list.
- ↓ - will navigate forward in the history list.
- b() - displays all the current variable bindings in the shell.
- f() - drops all the current variable bindings in the shell.
- f(Variable) - drops the specified variable binding in the shell.
navigate the filesystem
- pwd() - print working directory, the pwd() will start in the same directory as the shell were started.
- ls() - list directory contents.
- cd(Path) - change working directory, Path is a string, e.g. cd(“..”) or cd(“src”).
working with source code and modules
- c(File) - compiles the given file and loads the code in the shell. It will also make some extra work if you recompile the code so that no old code is running.
- lc(Files) - compiles the given files the same way as the command above.
- m() - displays all loaded modules in the shell.
- m(Module) - displays information about the given module.
The erlang shell is using the same key bindings as emacs when you are working/editing text in the shell.
- C-a - move the cursor to the beginning of the line.
- C-e - move the cursor to the end of the line.
- C-b - move the cursor left one character.
- C-f - move the cursor right one character.
This is just some basic stuff that is good to know about the erlang shell. There is a lot more stuff to know and learn about the shell like connect to remote shells, user switch command (Ctrl-G), working with records and more. However more about these things can be found in the links to the man pages at the beginning of this post.