Erlang Shell实用小技巧
浏览:1833次 出处信息
Erlang Shell下有很多内置的命令,在平时交互的时候很好用,文档里面都是一行带过,大家可能没什么感觉。
我来重点讲解和演示下:
$ erl Erlang R14B04 (erts-5.8.5) 1 [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) 1> help(). ** shell internal commands ** b() -- display all variable bindings e(N) -- repeat the expression in queryf() -- forget all variable bindings f(X) -- forget the binding of variable X h() -- history history(N) -- set how many previous commands to keep results(N) -- set how many previous command results to keep catch_exception(B) -- how exceptions are handled v(N) -- use the value of query rd(R,D) -- define a record rf() -- remove all record information rf(R) -- remove record information about R rl() -- display all record information rl(R) -- display record information about R rp(Term) -- display Term using the shell\'s record information rr(File) -- read record information from File (wildcards allowed) rr(F,R) -- read selected record information from file(s) rr(F,R,O) -- read selected record information with options
我最经常用的有以下几个,熟悉了感觉就很爽:
抹掉变量:
f() - forget all variables
f(X) - forget X
1> Pid=spawn(fun()-> receive _->ok end end). <0.33.0> 2> 2> Pid=spawn(fun()-> receive _->ok end end). ** exception error: no match of right hand side value <0.35.0> 3> f(Pid). ok 4> Pid=spawn(fun()-> receive _->ok end end). <0.39.0> 5> f(). ok 6> Pid=spawn(fun()-> receive _->ok end end). <0.42.0> 7>
找回命令执行结果:
v(42) - recall result from line 42
v(-1) - recall result from previous line
$ erl 1> spawn(fun()-> receive _->ok end end). %%忘记赋值,有spawn这样的命令有副作用,不能重复执行 <0.33.0> 2> Pid=v(-1). %% 补救 <0.33.0> 3> v(2). <0.33.0>
读入记录定义:
rr(foo) - read record definitions from module foo
$ touch test.dat
$ locate file.hrl
/usr/local/lib/erlang/lib/kernel-2.14/include/file.hrl
$ erl
1> file:read_file_info("test.dat"). %%信息很乱
{ok,{file_info,38914,regular,read_write,
{{2011,10,5},{14,56,49}},
{{2011,10,5},{14,56,49}},
{{2011,10,5},{14,56,49}},
33261,1,234881026,0,4577608,501,20}}
2>
2> rr("/usr/local/lib/erlang/lib/kernel-2.14/include/file.hrl").
[file_descriptor,file_info]
3>
3> file:read_file_info("test.dat"). %%自描述
{ok,#file_info{size = 38914,type = regular,
access = read_write,
atime = {{2011,10,5},{14,56,49}},
mtime = {{2011,10,5},{14,56,49}},
ctime = {{2011,10,5},{14,56,49}},
mode = 33261,links = 1,major_device = 234881026,
minor_device = 0,inode = 4577608,uid = 501,gid = 20}}
4>
找回命令历史记录:
h()
$ erl 1> X=1. 1 2> Y=2. 2 3> Z=3. 3 4> h(). 1: X = 1 -> 1 2: Y = 2 -> 2 3: Z = 3 -> 3 ok 5>
祝大家玩得开心!
建议继续学习:
- whatsapp深度使用Erlang有感 (阅读:5287)
- Erlang match_spec引擎介绍和应用 (阅读:5202)
- php-erlang (阅读:4887)
- gen_tcp调用进程收到{empty_out_q, Port}消息奇怪行为分析 (阅读:3945)
- hibernate使用注意事项 (阅读:3847)
- Erlang如何限制节点对集群的访问之net_kernel:allow (阅读:3594)
- Erlang linkin driver用port_control方式时的一些经验分享 (阅读:3533)
- ERLANG OTP源码分析 – gen_server (阅读:3262)
- erlang学习手记 (阅读:3243)
- gen_tcp容易误用的一点解释 (阅读:3092)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
扫一扫订阅我的微信号:IT技术博客大学习
<< 前一篇:Erlang match_spec引擎介绍和应用
后一篇:Erlang进程简单的主动负载管制实现 >>
文章信息
- 作者:Yu Feng 来源: Erlang非业余研究
- 标签: Erlang
- 发布时间:2011-10-14 13:42:35
建议继续学习
近3天十大热文
-
[918] WordPress插件开发 -- 在插件使用 -
[134] 解决 nginx 反向代理网页首尾出现神秘字 -
[54] 整理了一份招PHP高级工程师的面试题 -
[52] 海量小文件存储 -
[52] 如何保证一个程序在单台服务器上只有唯一实例( -
[52] 全站换域名时利用nginx和javascri -
[51] Innodb分表太多或者表分区太多,会导致内 -
[50] 用 Jquery 模拟 select -
[49] CloudSMS:免费匿名的云短信 -
[48] 分享一个JQUERY颜色选择插件
