如何使用Elixir制作单文件脚本,而不会产生过多的输出?

ijt*_*ijt 5 elixir

我想做一些似乎应该很简单的事情,即创建一个输出问候消息的脚本而不是其他内容.这个脚本非常简单,不需要多个文件.这是我试过的:

[ ~/elixir ] cat hello.exs
#!/usr/bin/env iex
IO.puts "Hello world!"
:init.stop

[ ~/elixir ] ./hello.exs
Erlang/OTP 17 [erts-6.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Hello world!
Interactive Elixir (1.0.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> [ ~/elixir ]
Run Code Online (Sandbox Code Playgroud)

这非常接近期望的结果,但我正在寻找像--quiet或--silent标志来抑制Erlang和Elixir启动消息.将-S标志添加到iex没有帮助:

[ ~/elixir ] cat hello.exs
#!/usr/bin/env iex -S
IO.puts "Hello world!"
:init.stop

[ ~/elixir ] ./hello.exs
Erlang/OTP 17 [erts-6.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

-S : Could not find executable ./hello.exs
Run Code Online (Sandbox Code Playgroud)

我知道有可能(http://goo.gl/MtFTQF)使用mix为此创建一个项目,但它看起来有点过分.我现在要做的就是制作一个简单的hello脚本.

Jos*_*lim 10

您应该使用elixir可执行文件来运行Elixir文件(#!/usr/bin/env elixir).iex将执行该文件并启动Interactive Shell.