Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Erlang Shell


May 13, 2021 Erlang


Table of contents


Erlang Shell

Most operating systems have command interpreters or shells, unix and Linux systems have many different shells, and there are command-line prompts on windows systems. Erlang can write Erlang code directly in his own shell and be executed with the effect of output execution (refer to the shell manual in STDLIB).

Start a shell or command interpreter in the Linux or Unix operating system, and then enter the erl command to start the erlang shell. A fter you start Erlang's shell, you can see the following output:

% erl
Erlang R15B (erts-5.9.1) [source] [smp:8:8] [rq:8] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9.1  (abort with ^G)
1>

Enter the enter "2 plus 5." in the shell, and then enter the carriage return. Note that the purpose of entering the character "." with the carriage return is to tell the shell that you have completed the code entry.

1> 2 + 5.
7
2>

As shown above, Erlang numbers all the lines that can be entered (e.g., sgt;1, sgt;2), and the example above means that the result of 2 plus 5 is 7. I f you enter the wrong contents in the shell, you can use the fallback key to remove it, which is the same as most shells. T here are many editing commands under the shell (refer to the tty-A command line interface documentation in the ERTS user guide).

(Note that many of the shell line numbers given in these examples are out of order.) T his is because the examples in this tutorial are separate testing procedures, not continuous ones, so there is a numbering disorder).

Here's a more complex calculation:

2> (42 + 77) * 66 / 3.
2618.0

Note the use of parentheses in which the multiplication operator """ and the division operator "/" have exactly the same meaning and usage as in general arithmetic operations. ( see Expression).

Entering the Ctrl and C keys stops the Erlang system from interacting with the command line (shell).

Here's the output after entering Ctrl-C:

BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
a
%

Enter "a" to end the Erlang system.

Another way to shut down the Erlang system is by entering halt():

3> halt().
%