【发布时间】:2011-10-01 10:14:31
【问题描述】:
我正在使用 pdl2 shell,如何列出我的所有命令历史记录?
【问题讨论】:
我正在使用 pdl2 shell,如何列出我的所有命令历史记录?
【问题讨论】:
您可以在 $HOME/.perldl_hist 中找到您的历史记录
这可能取决于是否安装了 Term::ReadLine::Gnu(我默认安装了)。
如果您想在pdl 中访问您的历史记录,那么只需使用向上箭头键来执行前面的命令,或者输入 ^R (control-r) 然后输入您要搜索的文本(点击 ^r重复进行更远的比赛)。
$ pdl
perlDL shell v1.354
...blah blah blah...
pdl> print 1+1
2
pdl> print 2+2
4
pdl> quit
$ cat ~/.perldl_hist
print 1+1
print 2+2
$
编辑:要从在 pdl 中查找历史记录,请执行以下操作:
$ pdl
pdl> print join "\n", $PERLDL::TERM->GetHistory
$PERLDL::TERM->GetHistory 返回当前历史记录的数组。它只是一个常规数组,所以你可以用它做任何你喜欢的事情。例如,要查找您最近所有涉及名为 mypdl 的 piddle 的直方图操作,您可以执行以下操作:
pdl> print join "\n", grep { /histogram/ && /mypdl/ } $PERLDL::TERM->GetHistory
【讨论】:
^z cat... 的可能性。好吧,下次如果我真的想在 pdl2 中看到它,我总是可以pdl> print qx{cat ~/.perldl_hist}。
pdl 中获取信息。请注意,您必须安装 Term::ReadLine::Gnu(首选)或 Term::ReadLine::Perl。
来自 PDL 文档(即pdldoc perldl):
History mechanism
If you have the perl modules ReadLines and ReadKeys installed, then
perldl supports a history and line-editing mechanism using editing keys
similar to emacs. The last 500 commands are always stored in the file
.perldl_hist in your home directory between sessions. Set
$PERLDL::HISTFILESIZE to change the number of lines saved. The command
"l [number]" shows you the last "number" commands you typed where
"number" defaults to 20.
【讨论】:
pdl2 shell 中开发计算方法后,您可以复制 .perldl_hist 文件并进行编辑以生成脚本/程序来执行相同的操作。