{"id":5144,"date":"2016-03-03T10:11:32","date_gmt":"2016-03-03T13:11:32","guid":{"rendered":"http:\/\/blog.plataformatec.com.br\/?p=5144"},"modified":"2016-03-03T16:42:13","modified_gmt":"2016-03-03T19:42:13","slug":"how-to-quit-the-elixir-shell-iex","status":"publish","type":"post","link":"http:\/\/blog.plataformatec.com.br\/2016\/03\/how-to-quit-the-elixir-shell-iex\/","title":{"rendered":"How to quit the Elixir shell (IEx)?"},"content":{"rendered":"
Okay, you’ve been delving into Elixir. That’s good! \ud83d\ude42<\/p>\n
Of course the first question that pops up in your head is not about immutability, concurrency nor functional programming.<\/p>\n
It is<\/p>\n
\n How can I quit the Elixir shell?\n<\/p><\/blockquote>\n
Today this question will be answered.<\/p>\n
Ctrl-C<\/h2>\n
When you start your
iex<\/code> sessions, you are greeted with:<\/p>\n
Interactive Elixir (1.2.2) - press Ctrl+C to exit (type h() ENTER for help)\niex(1)>\n<\/code><\/pre>\n
Ctrl-C<\/code> actually puts you into the Break command. From there, you can exit the shell using
(a)bort<\/code>:<\/p>\n
iex(1)>\nBREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded\n (v)ersion (k)ill (D)b-tables (d)istribution\na\ngeorge:~$\n<\/code><\/pre>\n
What I’m used to do is to hit
Ctrl-C<\/code> twice<\/strong>. It has the same effect as the
abort<\/code> command.<\/p>\n
The Break command can be triggered from any running Elixir code and not only
iex<\/code>. But I always feel this is somewhat dirty. That by dropping into the Break command and exiting from there, I’m leaving my session opened. I know this is not the case but I went to find other ways to exit the shell.<\/p>\n
Ctrl-G<\/h2>\n
You may have heard about
Ctrl-G<\/code>. If you type it in your IEx session, you’ll see:<\/p>\n
iex(1)>\nUser switch command\n<\/code><\/pre>\n
This drops you into the User switch command, or Job Control Mode (JCL), if you read about it in the Erlang documentation.<\/p>\n
In this mode, you can create new shells (local and remote ones), list and terminate them:<\/p>\n
User switch command\n --> h\n c [nn] - connect to job\n i [nn] - interrupt job\n k [nn] - kill job\n j - list all jobs\n s [shell] - start local shell\n r [node [shell]] - start remote shell\n q - quit erlang\n ? | h - this message\n -->\n<\/code><\/pre>\n
If you use
q<\/code> in this mode, you’ll halt your Erlang system, similar to aborting through the Break command. However Job Control Mode only works within IEx and therefore it is somewhat more restricted compared to
Ctrl+C<\/code>.<\/p>\n
Ctrl-\\<\/h2>\n
You may have tried
Ctrl-D<\/code>, a.k.a the End-of-Transmission character<\/a>. Turns out Erlang and Elixir don’t understand it the way we are used from other REPLs.<\/p>\n
What I didn’t know is that you can exit the shell by sending
Ctrl-\\<\/code>. The shell will exit immediately. As far as I know, it has the same effect as aborting the shell<\/strong> in the Break command, it doesn’t affect remote nodes<\/strong> and it also works outside of
iex<\/code> (for example, you can use to terminate your tests). I only found out about it in this brief passage<\/a> in the Erlang FAQ.<\/p>\n
Now that’s a quick and proper exit. My search is complete. Now I just need to retrain my muscle memory.<\/p>\n
\n
\n<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"Okay, you’ve been delving into Elixir. That’s good! \ud83d\ude42 Of course the first question that pops up in your head is not about immutability, concurrency nor functional programming. It is How can I quit the Elixir shell? Today this question will be answered. Ctrl-C When you start your iex sessions, you are greeted with: Interactive … \u00bb<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[143],"aioseo_notices":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts\/5144"}],"collection":[{"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/comments?post=5144"}],"version-history":[{"count":10,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts\/5144\/revisions"}],"predecessor-version":[{"id":5157,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts\/5144\/revisions\/5157"}],"wp:attachment":[{"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/media?parent=5144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/categories?post=5144"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/tags?post=5144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}