Elixir交互式Shell: 1. 运行时系统标记
Elixir交互式Shell: 2. 常用命令
Elixir交互式Shell: 3. 创建本地和远程Shell
Elixir交互式Shell: 4. 处理文件和脚本
Elixir交互式Shell: 5. 配置IEx
这是
IEx系列
五部分中的第二部分, 在这一部分中, 我们将说明如何使用IEx中的命令
补全
在IEx中数输入Elixir
, 让后按Tab
键, 显示不全的结果
iex(60)> Elixir.
Access Agent Application
ArgumentError ArithmeticError Atom
BadArityError BadFunctionError BadMapError
BadStructError Base Behaviour
Bitwise CaseClauseError Code
Collectable CompileError CondClauseError
Dict Elixir Enum
Enumerable ErlangError Exception
File Float FunctionClauseError
GenEvent GenServer HashDict
HashSet IEx IO
Inspect Integer Kernel
KeyError Keyword List
Logger Macro Map
MapSet MatchError Module
Node OptionParser Path
Port Process Protocol
Range Record Regex
RuntimeError Set Stream
String StringIO Supervisor
SyntaxError System SystemLimitError
Task TokenMissingError TryClauseError
Tuple URI UndefinedFunctionError
UnicodeConversionError Version
所有Enum
模块中以字母m
开头的函数
iex(60)> Enum.m
map/2 map_join/3 map_reduce/3 max/1
max_by/2 member?/2 min/1 min_by/2
min_max/1 min_max_by/2
帮助 (h/0
, h/1
)
通过h
命令, 我们可以查看模块文档, 模块中函数的文档
h/0
显示IEx.Helpers
文档h/1
显示某个模块, 函数的文档
显示模块文档
iex(60)> h Enum
显示函数文档
iex(62)> h Enum.reduce
文件和目录辅助功能
显示当前目录
iex(1)> pwd
/ElixirProjects/distributed/distro
列出当前目录中的文件和子目录, 和系统工具ls
类似
iex(2)> ls
.editorconfig .git .gitignore README.md _build
abc.sh bcd.sh config def.sh deps
erl_crash.dump lib mix.exs mix.lock rel
test
重启当前IEx Shell, 值编号变为(1)
iex(4)> respawn
Interactive Elixir (1.2.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
详细的命令列表可以直接在IEx Shell中键入h
查看
iex(1)> h
...
• b/1 - prints callbacks info and docs for a given module
• c/2 - compiles a file at the given path
• cd/1 - changes the current directory
• clear/0 - clears the screen
• flush/0 - flushes all messages sent to the shell
• i/1 - prints information about the given data type
• h/0 - prints this help message
• h/1 - prints help for the given module, function or macro
• import_file/1 - evaluates the given file in the shell's context
• l/1 - loads the given module's beam code
• ls/0 - lists the contents of the current directory
• ls/1 - lists the contents of the specified directory
• pid/3 — creates a PID with the 3 integer arguments passed
• pwd/0 — prints the current working directory
• r/1 — recompiles and reloads the given module's source file
• respawn/0 — respawns the current shell
• s/1 — prints spec information
• t/1 — prints type information
• v/0 — retrieves the last value from the history
• v/1 — retrieves the nth value from the history
• import_file/1 — evaluates the given file in the shell's context
...
iex(2)>
访问前一个值
➜ iex
iex(1)> :os.timestamp
{1460, 298263, 550140}
iex(2)> v(-1)
{1460, 298263, 550140}
iex(3)> v(2)
{1460, 298263, 550140}
#iex:break
当输入错误, 无论如何也无法结束的时候输入 #iex:break
结束当前行的输入, 而不必使用Ctrl + C
结束IEx 会话.
可以试试下面的输入, 可以看到#iex:break
的效果
iex(60)> list = [
...(60)> :a, "abc, :b]
...(60)> "
...(60)> ???
iex:63: warning: found ? followed by codepoint 0xA (newline), please use \n instead
...(60)> ;
iex:63: warning: found ? followed by codepoint 0xA (newline), please use \n instead
...(60)> .
iex:63: warning: found ? followed by codepoint 0xA (newline), please use \n instead
...(60)> #iex:break