Search code examples
erlangerlang-shell

How can I exit a multi-line command sequence in the Erlang shell?


Sometimes in the Erlang shell, if I mistype a command and hit Enter, the shell goes to the next line in anticipation that the command will continue (so the line number on the left stays the same).

For example, I just now mistakenly (on purpose) typed 1> $"X". instead of 1> $X.. After hitting Enter, now the command line is stuck on 1>. I have tried typing . followed by Enter and simply Enter in the hopes of terminating the command sequence, but it doesn't work. Although I have tried, it is very hard to look this up on google because the incredibly common keywords lead to other results.

Is there a way I can break that sequence without having to exit the shell entirely with Ctrl C? The trouble with restarting the shell is all the variables are lost.


Solution

  • you can hit Ctrl-g, which gets you to the "User switch command" this erlang's shell break mode

    The prompt will change from > to --->.

    In this mode

    • Type i to interrupt your erlang session
    • then type c to reconnect to it

    erlang shell will then state exception exit: killed and return to the state it was in immediately before you got stuck.

    ~ → erl
    Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
    
    local recon loaded
    local stdlib2 loaded
    Eshell V8.2  (abort with ^G)
    1> $"X".
    1> l
    1> .
    1> .
    1>
    User switch command
     --> i
     --> c
    ** exception exit: killed
    1> R=22.
    22
    2> $"X".
    2>
    User switch command
     --> i
     --> c
    ** exception exit: killed
    2> b().
    R = 22
    ok
    3>